各位好!
上位机发送数据,
单片机接收后再将同样的数据发送出来,但是发送出来的数据会丢失1~2个数据,不知道怎么回事,望解答!
- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar flag,i;
- uchar temp;
- uchar code table[] = "I get ";
- void initial();
- void main()
- {
- initial();
- while(1)
- {
- if(flag == 1)
- {
- ES = 0;
- /*for(i=0;i<6;i++)
- {
- SBUF = table[i];
- while(!TI);
- TI = 0;
- }*/
- SBUF = temp;
- while(!TI);
- TI = 0;
- ES = 1;
- flag = 0;
- }
- }
- }
- void serial()interrupt 4
- {
- temp = SBUF;
- flag = 1;
- RI = 0;
- }
- void initial()
- {
- TMOD = 0x20;
- TH1 = 0xfd;
- TL1 = 0xfd;
- TR1 = 1;
- REN = 1;
- SM0 = 0;
- SM1 =1;
- EA = 1;
- ES = 1;
- }
复制代码
一周热门 更多>