完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include #define uchar unsigned char #define uint unsigned int void sand1(uchar *receive); uchar buf; uchar flag = 0; uchar i=0; uchar Receive[20]; void main() { SCON = 0X50;//串口方式1,允许接收 PCON = 0X00;//波特率不加倍 TMOD = 0X20;//定时器方式2 EA = 1; ES = 1; TH1 = 0XFD;//波特率9600 TL1 = 0XFD; TR1 = 1; if(flag == 1) { for(i = 1;(i<21)&&(buf!=-1); i++)//-1表示写入字符串的结束标志 { Receive[i-1]=buf; flag = 0; } } while(1) { sand1(Receive); } } //下位机串口接收中断 void shou_xia() interrupt 4 { ES = 0; if(RI == 1) { RI = 0; buf = SBUF; } flag = 1; ES = 1; } void sand(uchar dat) { SBUF=dat;//向pc发送单个字符 while(ti == 0);//等待发送 TI = 0; } void sand1(uchar *receive) { while(*receive!=' |