本帖最后由 happywei 于 2014-5-9 09:40 编辑
求教高手我向51单片机发送数据,就会返回数据,当接受1b 25 41,或1b 25 42,1b 25 43或1b 25 4b命令时就不转发,且执行相应的操作,我现在遇到的问题是当发1b 25 41时,会返回1b 25,按要求应该是要不返回数据
程序如下,求高手指点
void serial() interrupt 4
{
RI=0; //清除接收中断
RecTmp = SBUF ;
switch (CMD_state)
{
case 0:
if(RecTmp == 0x1b) {
// maybe CMD!
CMD_state = 1 ;
CMD_flag1=1;
flag=1;
}
else
{
flag=0;
CMD_flag1=0;
CMD_state = 0 ;
}
break ;
case 1:
if (RecTmp == 0x25)
{
flag=1;
CMD_state = 2 ;
CMD_flag2=1;
}
else
{
flag=0;
CMD_flag1=0;
CMD_flag2=0;
CMD_state = 0 ;
}
break ;
case 2:
CMD3 = RecTmp ;
switch(CMD3)
{
case 0x41:
case 0x42:
case 0x43:
case 0x4b:
CMD_flag3 = 1 ;
CMD_flag = 1 ;
flag=1;
break;
default:
flag=0;
CMD_flag1=0;
CMD_flag2=0;
CMD_flag3 = 0 ;
CMD_state = 0 ;
break;
}
break ;
}
if(flag==1)
{
flag_aa=1;
if(CMD_flag3 == 1)
{
flag=0;
CMD_flag1=0;
CMD_flag2=0;
CMD_flag3 = 0 ;
CMD_state = 0 ;
flag_aa=0;
}
else
{
table[Rx_i] = RecTmp ;
Rx_i ++ ;
if(Rx_i == table_size)
Rx_i = 0 ; // 到table结尾了,从头0再来
flag_aa=0;
}
}
else
{
if(flag_aa==0)
{
if( (Rx_i + 1) == Tx_i)
{
//满
}
else
{
table[Rx_i] = RecTmp ;
Rx_i ++ ;
if(Rx_i == table_size)
Rx_i = 0 ; // 到table结尾了,从头0再来
}
}
}
}
|