Home > other >  51 microcontroller through the serial port communication of two problems
51 microcontroller through the serial port communication of two problems

Time:09-17

I use the host lattice got a 9-0 seconds countdown, from machine to send the host key value (host countdown timer 0, a serial port using the timer, serial port communication is ok), I am using Proteus simulation
I in order to realize the function of the is: from the scanning machine to press the button, the host began to show the countdown,
I now the question is:
My lattice can only display 9 (8) will not become, I show is on the serial port interrupt, timer 0 only to timing (50 ms an overflow), a serial port baud rate 4800
Excuse me: 1. The interruption of display function should be in what place, or a while loop
2. The interrupt priority need not to need to change
The great god, please help me,
Look at where you need to modify,
This is the code
 
U8 Time=0, the second=0;
U8 Val=0;

Void zhongduan_Init (void)
{
TMOD=0 x21;//open timer 0, 1
TH0=0 x3c;//set the initial value, timing 50 ms
TL0=0 xb0;
TH1=0 xf3;//counter initial value is set, pay attention to the baud rate is 4800
TL1=0 xf3;
ET0=1;//open the timer 0 interrupt
TR0=0;//do not start the timer 0
TR1=1;//open the timer 1
SM0=0;//set the serial port works
The SM1=1;
REN=1;//open the serial port receiving interrupt
IP=0 x10;
EA=1;//open the total interruption
ES=1;//open the serial port interrupt

}
Void main ()
{
Zhongduan_Init ();
While (1)
{
}

}
Void Timer0 interrupt ()
1//interrupt service function{
TH0=0 x3c;
TL0=0 xb0;
Time++;
If (Time==20)
{
Time=0;
Second++;//for a second time
//if (second>=1) convert ();//heart-shaped shift
}
}
Void Usart interrupt ()
4{
Val=SBUF;
The switch (Val)
{
Case 1:
The display (Val);//show
break;
}
RI=0;
}



 
Void the display (u8 DATa)//dot matrix display function
{
U8 j;
P0=0 x7f;

The switch (DATa)
{
Case 0://initial screen
for(j=0; j<8; J++)
{
P0=bubian [j];
Senddata publishes the event (ten [j]);
Delay (10);
Senddata publishes the event (0 x00);//blanking
}
break;
Case 1:
Show_1 ();
break;
}
}
Void show_1 (void)//countdown display
{
U8 j;
TR0=1;//open timer

While (second{
for(j=0; j<8; J++)
{
P0=bubian [j];
Senddata publishes the event (count [second] [j]);
Delay (5);
Senddata publishes the event (0 x00);//blanking
}
}
}




  • Related