Home > other >  Single-chip microcomputer serial port control timer time
Single-chip microcomputer serial port control timer time

Time:09-28

Use a serial port receives the digital timer as time

# include

Unsigned int I, num;


Sbit led0=P2 ^ 0;

//IP=0 x10;
Void main (void)
{
//
IP=0 x10;
TMOD=0 x21;

TH0=0 x0ff;
TL0=0 x9c;
EA=1;
ET0=1;
TR0=1;

SCON=0 x50;
TH1=0 xf3;
TL1=TH1;
PCON=0x00;
EA=1;
ES=1;
TR1=1;
While (1)
{
If (num==I)
{
Num=0;
Led0=~ led0;
}
}
}

Void Timer0Interrupt (void) interrupt 1
{
TH0=0 x0ff;
TL0=0 x9c;
Num++;
}

Void UARTInterrupt (void) interrupt 4
{
If (RI)
{
I=SBUF;
RI=0;
}

}


Not on the single chip microcomputer experiment, cannot effectively control, ask bosses look, some guidance

CodePudding user response:

Define when I, num two variables add a modifier static try

CodePudding user response:

Phenomenon is to be able to realize, but you can't control it, it should be set your timer timing time too short, so you are a serial port the value of the corresponding larger, otherwise can't keep up with num value change, suggest you control the value of the timer timing

CodePudding user response:

reference 1st floor hellojef response:
define when I, num two variables add a modifier static try
no, would it be to send the data type of the what's the problem, I use a serial debugging assistants send

CodePudding user response:

Problems should be out in the timer, can return to the correct data

# include
# define uchar unsigned char
# define uint unsigned int

Uint num.
Uint I [1];
Uchar flag;

Sbit led=P2 ^ 0;

/* void delay100us (void)
{
Unsigned char a, b;
For (b=1; B> 0; B -)
For (a=47; A> 0; A -);
} */


Void main (void)
{
IP |=0 x10;
TMOD |=0 x21;
EA=1;


TH0=0 x0fc;
TL0=0 x18;
ET0=1;
TR0=1;

SCON=0 x50;
TH1=0 xe6;
TL1=TH1;
PCON=0x00;
ES=1;
TR1=1;

while(1);
/* {

If (num==I)
{
Num=0;
Led0=~ led0;
}

} */
}


Void Timer0Interrupt (void) interrupt 1
{
TH0=0 x0fc;
TL0=0 x18;
Num++;
If (num==I [0])
{
Num=0;
Led=~ led;
}
}

Void UARTInterrupt (void) interrupt 4
{
Uint j;
If (RI)
{
RI=0;
J=SBUF;
I [0]=j;
SBUF=I [0];
}
If (TI)
TI=0;
}
  • Related