/***************串口中斷程序***************/
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;} //若接收到的數(shù)據(jù)前面接收到了0X10 則過濾掉
else{com_bus[a]=c; a++; if(c==0x03){bz=1;}} //若接收的數(shù)據(jù)前面沒有0x10則送入緩沖區(qū) 若接收到0x03 則置接收完成標(biāo)志
}
else {com_bus[a]=c; a++; if(c!=0x02) {b=0;} } //若接收數(shù)據(jù)幀頭不對,則跳出接收
}
else
{
com_bus[a]=c; a++; //若接收數(shù)據(jù)幀頭不對,則跳出接收
if(com_bus[0]!=0x02) {b=0;}
}
if(com_bus[0]==0x02&&c==0x03&&bz==1)
{
b=0;
bz=0;
}
}
ES=1;
} |