/***************串口中断程序***************/
void com() interrupt 4 using 2
{
uchar a=0,c=0;
uint b=65535;
ES=0;
while(b--)
{
while(!RI);
RI=0;
c=SBUF;
if(c==0x10||c==0x02||c==0x03)
{
if(a!=0)
{
if(com_bus[a-1]==0x10) {com_bus[a-1]=c;} //若接收到的数据前面接收到了0X10 则过滤掉
else{com_bus[a]=c; a++; if(c==0x03){bz=1;}} //若接收的数据前面没有0x10则送入缓冲区 若接收到0x03 则置接收完成标志
}
else {com_bus[a]=c; a++; if(c!=0x02) {b=0;} } //若接收数据帧头不对,则跳出接收
}
else
{
com_bus[a]=c; a++; //若接收数据帧头不对,则跳出接收
if(com_bus[0]!=0x02) {b=0;}
}
if(com_bus[0]==0x02&&c==0x03&&bz==1)
{
b=0;
bz=0;
}
}
ES=1;
} |