#include<reg51.h>
#define uchar unsigned char
uchar rec[12];
uchar code dd[9]="+IPD,0,2:";
uchar num;
bit uartflag;
sbit p10=P1^0;
void uart() interrupt 4
{
uchar dat,i;
if(RI)
{
RI=0;
dat=SBUF;
if(dat=='+')
{
num=0;
}
rec[num]=dat;
num++;
if(num>=11)uartflag=1;
}
}
main()
{
uchar i,error;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
SCON=0x50;
TR1=1;
ES=1;
EA=1;
uartflag=0;
num=0;
while(1)
{
if(uartflag)
{
error=0;
for(i=0;i<9;i++)
{
if(dd[i]!=rec[i]error=1;
}
if(error==0)
{
if(rec[9]=='0' && rec[10]=='1')p10=0;
else if(rec[9]=='8' && rec[10]=='9')p10=1;
}
}
}
}
追问感谢你的回答,但是程序有错误,不能生产hex文件