📄 com0int.c
字号:
/********************************************************************
包含头文件
********************************************************************/
#include "PL3200.H"
#include "CONST.H"
#include "RAM.H"
#include "IO.H"
/********************************************************************
函数名称: void Com0Int(void) interrupt 6
功 能: 串口1中断接收处理
入 口: 无
出 口: COM0_RECE_OK COM0_RECE_OK='C',接收普通帧成功
COM0_RECE_OK='F',接收特殊帧成功
其他:未成功接收数据帧
--------------------------------------------------------------------
说 明: a、串口接收成功判断
1、普通帧
1)依次接收到'S' 'N' 'D'
2)接收到的数据长度大于18、小于100时为合法
3)依次接收到固定数据0xff 0xff 0xff 0xff 0xff 0xff 0x09 0xaf
4)按长度接收后续数据,校验要正确
2、特殊帧
1)依次接收到'C' 'I' 'D' 0x0d 0x0a
b、串口配置:9600bps,偶校验
********************************************************************/
void Com0Int(void) interrupt 6
{
if(ERI)
{
uint8 i,sbuf_temp,temp ;
bit even_bit=0 ;
ERI = 0 ;
com0_tmr = 60 ;
sbuf_temp = SBUF1 ;
temp = SBUF ;
for(i=0;i<8;i++)
{//判断数据是否为偶校验
if((temp&0x80)==0x80)
{
even_bit = !even_bit ;
}
temp = (temp<<1) ;
}
if(even_bit!=RB8)
{
com0_tmr = 2 ;
return ;
}
if(com0_step==0)
{
if(sbuf_temp=='S')
{//接收'S'
comd_sel_bit = 0 ;
com0_rece_ptr = 0 ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_step = 1 ;
}
else
{//接收'C'
if(sbuf_temp=='C')
{
comd_sel_bit = 1 ;
com0_step = 1 ;
}
}
}
else if(com0_step==1)
{
if(!comd_sel_bit)
{
if(sbuf_temp=='N')
{//接收'N'
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_step = 2 ;
}
else
{
com0_step = 0 ;
}
}
else
{
if(sbuf_temp=='I')
{//接收'I'
com0_step = 2 ;
}
else
{
com0_step = 0 ;
}
}
}
else if(com0_step==2)
{
if(!comd_sel_bit)
{//接收'D'
if(sbuf_temp=='D')
{
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_step = 3 ;
}
else
{
com0_step = 0 ;
}
}
else
{
if(sbuf_temp=='D')
{//接收'D'
com0_step = 3 ;
}
else
{
com0_step = 0 ;
}
}
}
else if(com0_step==3)
{
if(!comd_sel_bit)
{
if((sbuf_temp>=18)&&(sbuf_temp<(com1_rece_buf_len-5)))
{//接收数据长度
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_rece_len = 6 ;
com0_step = 4 ;
}
else
{
com0_step = 0 ;
}
}
else
{
if(sbuf_temp==0x0d)
{
com0_step = 4 ;
}
else
{
com0_step = 0 ;
}
}
}
else if(com0_step==4)
{
if(!comd_sel_bit)
{
if(sbuf_temp==0xff)
{//接收6字节FFH
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_rece_len-- ;
if(com0_rece_len==0)
{
com0_step = 5 ;
}
}
else
{
com0_step = 0 ;
}
}
else
{
if(sbuf_temp==0x0a)
{
COM0_RECE_OK = 'F' ;
}
com0_step = 0 ;
}
}
else if(com0_step==5)
{//接收09H
if(sbuf_temp==0x09)
{
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_step = 6 ;
}
else
{
com0_step = 0 ;
}
}
else if(com0_step==6)
{//接收AFH
if(sbuf_temp==0xaf)
{
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_step = 7 ;
com0_rece_len = com0_rece_buf[3]-10 ;
com0_rece_crc = 0 ;
}
else
{
com0_step = 0 ;
}
}
else if(com0_step==7)
{//接收载波帧
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
com0_rece_crc = com0_rece_crc+com0_rece_buf[com0_rece_ptr] ;
com0_rece_len-- ;
if(com0_rece_len==0)
{
com0_step = 8 ;
}
}
else if(com0_step==8)
{
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
if(com0_rece_buf[com0_rece_ptr]==((uint8)(com0_rece_crc%256)))
{
com0_step = 9 ;
}
else
{
com0_step = 0 ;
}
}
else if(com0_step==9)
{
com0_rece_ptr++ ;
com0_rece_buf[com0_rece_ptr] = sbuf_temp ;
if(com0_rece_buf[com0_rece_ptr]==((uint8)(com0_rece_crc/256)))
{
for(i=0;i<(com0_rece_buf[3]+4);i++)
{
com0_rece_buf_bak[i] = com0_rece_buf[i] ;
}
COM0_RECE_OK = 'C' ;
com0_step = 0 ;
}
else
{
com0_step = 0 ;
}
}
else
{
com0_step = 0 ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -