📄 16c554.c
字号:
con_port |= WRITE_EN; //关闭写功能
for(j = 0; j < 110; j++); //发送数据延时
con_port = con_leisure; //控制端口设置为空闲
}
/****************************************************
*
* 函数名称:init_modem()
* 功能:modem初始化
* 入口:无
*
****************************************************/
void init_modem(void)
{
send_data_554(M_com_initf,num1,2); //at b0 p e1 q1 s0=1 &y1 &w1
delays(1); //延时
}
/****************************************************
*
* 名称: init_parameter
* 功能: 初始化各参数
* 调用: none
* 输入: none
* 返回值: none
*
****************************************************/
void init_parameter(void)
{
unsigned char i;
/*初始化A口各参数*/
Rx_in_554a = 0;
Rx_554a_start = 0;
data_num_554a = 0;
Rx_full_554a = 0;
checksuma = 0;
rx_temp1_554a = 0;
rx_temp2_554a = 0;
/*初始化B口各参数*/
Rx_in_554b = 0;
Rx_554b_start = 0;
data_num_554b = 0;
Rx_full_554b = 0;
checksumb = 0;
rx_temp1_554b = 0;
rx_temp2_554b = 0;
/*初始化C口各参数*/
Rx_in_554c = 0;
Rx_554c_start = 0;
data_num_554c = 0;
Rx_full_554c = 0;
checksumc = 0;
rx_temp1_554c = 0;
rx_temp2_554c = 0;
rx_temp3_554c = 0;
/*初始化D口各参数*/
Rx_in_554d = 0;
Rx_554d_start = 0;
data_num_554d = 0;
Rx_full_554d = 0;
checksumd = 0;
rx_temp1_554d = 0;
rx_temp2_554d = 0;
for(i = 0; i < 4; i++)
{
Rx_flag_554[i] = 0;
Rx_out_554[i] = 0;
}
interrupt_edge &= 0xf0; //上升沿触发中断
interrupt_en |= 0x0f; //中断允许位
interrupt_flag &=0x00;
// _EINT();
}
/****************************************************
*
* 名称: interrupt_554
* 功能: 554的中断处理函数
* 调用: none
* 输入: none
* 返回值: none
*
****************************************************/
/* ISR定义:
值 模式 优先级 定义(中断源)
01 16c450 x 没有中断
06 16c450 1 LSR(接收线路状态寄存器)
04 16c450 2 RXRDY(接收中断)
0C 16c450 2 RXRDY(接收超时中断)
02 16c450 3 TXRDY(发送寄存器空)
00 16c450 4 MSR(Modem状态寄存器)
C1 FIFO x 没有中断
C6 FIFO 1 LSR(接收线路状态寄存器)
C4 FIFO 2 RXRDY(接收中断)FIFO超出预定水平
CC FIFO 2 RXRDY(接收超时中断)
C2 FIFO 3 TXRDY(发送寄存器空)
C0 FIFO 4 MSR(Modem状态寄存器)
*/
void interrupt_554(void)
{
unsigned char status_554aisr; //554A口的ISR
unsigned char status_554cisr;
unsigned char status_554bisr;
unsigned char status_554disr;
unsigned char status_554cmsr; //状态存储器
unsigned char push; //堆栈,保存控制信号的状态
unsigned char i;
push = con_port; //con_port的状态保存
data_port_dir = 0x00; //数据信号输入
con_port = con_leisure;
con_port |= ISR;
con_port &= ~CSA;
con_port ^= READ_EN;
status_554aisr = data_in_port; //A口的ISR寄存器
con_port = con_leisure;
con_port |= ISR;
con_port &= ~CSB;
con_port ^= READ_EN;
status_554bisr = data_in_port; //B口
con_port = con_leisure;
con_port |= ISR;
con_port &= ~CSC;
con_port ^= READ_EN;
status_554cisr = data_in_port; //C口
con_port = con_leisure;
con_port |= ISR;
con_port &= ~CSD;
con_port ^= READ_EN;
status_554disr = data_in_port; //D口
con_port = con_leisure;
/* 判断是哪个口产生的中断 */
if((status_554aisr & 0x01) == 0) //判断是否是A口产生的中断
{
switch(status_554aisr) //中断类型选择
{
case 0x04: //接收中断
case 0x0c:
if(!Rx_full_554a) //缓冲区未满
{
con_port |= LSR;
con_port &= ~CSA;
con_port ^= READ_EN; //LSR
while((data_in_port & 0x01) == 0 ) //接收寄存器是否有数据
{
con_port = con_leisure;
con_port |= LSR;
con_port &= ~CSA;
con_port ^= READ_EN; //LSR
}
con_port = con_leisure;
con_port |= RHR;
con_port &= ~CSA;
con_port ^= READ_EN; //rhr
rx_temp2_554a = data_in_port; //接收到的数据存入数组
con_port = con_leisure;
if(Rx_554a_start) //判断是否开始接收数据包
{
rxdata[2+0][Rx_in_554a] = rx_temp2_554a;//数据存入缓冲数组
data_num_554a++; //接收到的数据个数
Rx_in_554a++;
if(data_num_554a == data_maxa) //判断是否接收完一个数据包
{
checksuma=0;
for (i=2;i<data_maxa-1;i++)
checksuma+=rxdata[2+0][i];
if(checksuma == rxdata[2+0][Rx_in_554a-1]) //校验和判断
port554_r=2;
else
{
for (i=0;i<data_maxa-1;i++)
rxdata[2+0][i]=0;
}
//////////////////////////////////
// command_oper(2);
Rx_554a_start = 0; //标志位清零
data_num_554a = 0;
Rx_flag_554[0]++; //数据包个数
Rx_in_554a = 0;
}
else if(data_maxa-data_num_554a != 1)
checksuma += rx_temp2_554a;
}
else if( ( rx_temp1_554a == 0xEB) && (rx_temp2_554a == 0x90) ) //数据包的包头
{
Rx_in_554a = 0;
rxdata[2+0][Rx_in_554a] = 0xeb; //包头数据存入缓冲数组
Rx_in_554a++;
rxdata[2+0][Rx_in_554a] = 0x90;
Rx_in_554a++;
checksuma =0;
Rx_554a_start = 1; //标志位置1
data_num_554a = 2;
}
else rx_temp1_554a = rx_temp2_554a;
}
else //缓冲数组已满
{
Rx_full_554a = 0; //没有溢出就把溢出标志清零
Rx_in_554a = 0;
con_port |= RHR;
con_port &= ~CSA;
con_port ^= READ_EN; //rhr
rx_temp1_554a = data_in_port; //接收到的数据存入数组
con_port = con_leisure;
}
break;
default:break;
}
if((P2IN & 0x01) == 0)
{
P2IFG &= 0x0fe; //清中断标志位
}
}
if((status_554bisr & 0x01) == 0) //判断是否是B口产生的中断
{
switch(status_554bisr) //中断类型选择
{
case 0x04: //接收中断
case 0x0c:
if(!Rx_full_554b) //缓冲区未满
{
con_port |= LSR;
con_port &= ~CSB;
con_port ^= READ_EN; //LSR
while((data_in_port & 0x01) == 0 ) //接收寄存器是否有数据
{
con_port = con_leisure;
con_port |= LSR;
con_port &= ~CSB;
con_port ^= READ_EN; //LSR
}
con_port = con_leisure;
con_port |= RHR;
con_port &= ~CSB;
con_port ^= READ_EN; //rhr
rx_temp2_554b = data_in_port; //接收到的数据存入数组
con_port = con_leisure;
if(Rx_554b_start) //判断是否开始接收数据包
{
rxdata[2+1][Rx_in_554b] = rx_temp2_554b;//数据存入缓冲数组
data_num_554b++; //接收到的数据个数
Rx_in_554b++;
if(data_num_554b == data_maxb) //判断是否接收完一个数据包
{
checksumb=0;
for (i=2;i<data_maxa-1;i++)
checksumb+=rxdata[2+1][i];
if(checksumb == rxdata[2+1][Rx_in_554b-1]) //校验和判断
port554_r=3;
// command_oper(3);
//////////////////////////////////
Rx_554b_start = 0; //标志位清零
data_num_554b = 0;
Rx_flag_554[1]++; //数据包个数
Rx_in_554b = 0;
}
else if(data_maxb-data_num_554b != 1)
checksumb += rx_temp2_554b;
}
else if( ( rx_temp1_554b == 0xEB) && (rx_temp2_554b == 0x90) ) //数据包的包头
{
Rx_in_554b = 0;
rxdata[2+1][Rx_in_554b] = 0xeb; //包头数据存入缓冲数组
Rx_in_554b++;
rxdata[2+1][Rx_in_554b] = 0x90;
Rx_in_554b++;
checksumb =0;
Rx_554b_start = 1; //标志位置1
data_num_554b = 2;
}
else rx_temp1_554b = rx_temp2_554b;
}
else //缓冲数组已满
{
Rx_full_554b = 0; //没有溢出就把溢出标志清零
Rx_in_554b = 0;
con_port |= RHR;
con_port &= ~CSB;
con_port ^= READ_EN; //rhr
rx_temp1_554b = data_in_port; //接收到的数据存入数组
con_port = con_leisure;
}
break;
default:break;
}
if((P2IN & 0x01) == 0)
{
P2IFG &= 0x0fd; //清中断标志位
}
}
if((status_554cisr & 0x01) == 0) //C口中断
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -