1 #include <reg51.h> 2 3 int flag = 0; 4 unsigned int Send_Data,Recv_Data; 5 6 void main() 7 { 8 SCON = 0X50; //MODE 2 9 TMOD = 0x20; //MODE 2 10 11 TH1 = 0XFD; 12 TL1 = 0XFD; 13 14 TR1 = 1; 15 ES = 1; //开串口中断 16 EA = 1; 17 18 while(1) 19 { 20 if(flag == 1) 21 { 22 SBUF = Send_Data; 23 while(TI == 0); 24 TI = 0; 25 flag = 0; 26 } 27 } 28 } 29 30 void ser_int() interrupt 4 //3定时器1的中断号 1定时器0的中断号 0外部中断1 2外部中断2 4串口中断 31 { 32 if(RI == 1) 33 { 34 RI = 0; 35 Recv_Data = SBUF; 36 Send_Data = Recv_Data; 37 flag = 1; 38 } 39 }
时间: 2025-01-10 07:05:02