#include
# define uchar unsigned char
# define uint unsigned int
Uchar receive [5].
Uchar address=5;
Uchar I, j; Uint ii; Uchar ij=0;
Uchar effect_flag=0;//valid data symbol
Sbit P31=P3 ^ 1; Sbit P32=P3 ^ 2; Sbit P33=P3 ^ 3; Sbit P34=P3 ^ 4; Sbit P35=P3 ^ 5; Sbit P37=P3 ^ 7;
Uchar code DSY_CODE []={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x00 to 0 x77, 0 x40};//the digital tube code
Void delay (uint x)
{
For (I=x; I> 0; I -)
For (j=115; J> 0; J -);
}
Void main ()
{
P31=0;//read address
Delay (6000);
Address=P1;
P31=1;
SCON=0x50;//serial interface mode 1, allowed to accept
TMOD=0 x20;//T1 in mode 2
PCON=0 x00;//baud rate not multiply
TH1=TL1=0 XFD;
ES=1;//allow the serial port interrupt
TR1=1;//start the timer 1
The receive [0]=11;//address processing, ready to display
The receive [1]=12;
The receive [2]=address/100;
The receive 10% [3]=address/10;
The receive [4]=address % 10;
For (ii=0; Ii<500; Ii++)//show address
{
P37=0; P35=1; P34=1; P33=1; P32=1; P1=DSY_CODE [the receive [0]]; Delay (3);
P37=1; P35=0; P34=1; P33=1; P32=1; P1=DSY_CODE [the receive [1]]; Delay (3);
P37=1; P35=1; P34=0; P33=1; P32=1; P1=DSY_CODE [the receive [2]]; Delay (3);
P37=1; P35=1; P34=1; P33=0; P32=1; P1=DSY_CODE [the receive [3]]; Delay (3);
P37=1; P35=1; P34=1; P33=1; P32=0; P1=DSY_CODE [the receive [4]]; Delay (3);
}
for(i=0; I<5; I++) {receive [I]=0; }//remove address
EA=1;//always interrupt
RI=0;
While (1)
{
P37=0; P35=1; P34=1; P33=1; P32=1; P1=DSY_CODE [the receive [0]]; Delay (3);
P37=1; P35=0; P34=1; P33=1; P32=1; P1=DSY_CODE [the receive [1]]; Delay (3);
P37=1; P35=1; P34=0; P33=1; P32=1; P1=DSY_CODE [the receive [2]]; Delay (3);
P37=1; P35=1; P34=1; P33=0; P32=1; P1=DSY_CODE [the receive [3]]; Delay (3);
P37=1; P35=1; P34=1; P33=1; P32=0; P1=DSY_CODE [the receive [4]]; Delay (3);
}
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//serial port receive interrupt function
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void Serial_INT () interrupt 4
{
If (RI==0) return;
ES=0;//close the serial port interrupt
If (effect_flag==1)
{
The receive [ij]=SBUF;//read characters
Ij++; If (ij==5) {ij=0; Effect_flag=0; }
}
If (SBUF==address) effect_flag=1;//setting valid data symbol
RI=0;
ES=1;//a serial port interrupt
}
The simulation diagram
CodePudding user response:
Is a serial port interrupt, not timing interrupt, others do not send a serial port, you won't produce receiving interrupt of MCU,