📄 lna3.c.bak
字号:
length--;
break;
case poffset2: Prmter1.POFFSET2=*P++ ;
wrom(poff2add,Prmter1.POFFSET2);
// buff=rrom(poff2add);
// if(buff!=Prmter1.POFFSET2)
// {
// wrom(poff2add,Prmter1.POFFSET2);
// }
length--;
break;
case ctrbb: Prmter1.CTRBB=*P++ ;
wrom(ctrbbadd,Prmter1.CTRBB);
// buff=rrom(ctrbbadd);
// if(buff!=Prmter1.CTRBB)
// {
// wrom(ctrbbadd,Prmter1.CTRBB);
// }
length--;
break;
default: receive_buf[9] = *--P;
receive_buf[8] = *--P;
erro = erro | 0x02;
length = 0;
break;//特殊处理
}
}
if(erro & 0x02)
{
length = 2;//设置参数失败
// receive_buf[4] = 0x05;
}
else
{
length = receive_buf[7];
}
return length;
}
/**********************************************************
** 功能说明: 参数查询函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 参数个数
** 引用函数:
** 创 建 人: 陈璐 创建时间:2005/01/11
*********************************************************/
uchar Query_Parameter()
{
auto union buf_union comm;
uchar length;
uchar * P1 = 0;
erro = 0;
P1 = receive_buf+8;
length = receive_buf[7];
while(length)
{
comm.buf2[0] = *P1++;
comm.buf2[1] = *P1++;
length = length - 2;
switch(comm.buf1)
{
case maxpwr: * P1++ = Prmter1.max;
length--;
break;
case gcu1: * P1++ = Prmter1.GCU1;
length--;
break;
case gcu2: * P1++ = Prmter1.GCU2;
length--;
break;
case maxpu: * P1++ = Prmter1.maxu;
* P1++ = 0;
length--;
length--;
break;
case idst: * P1++ = Prmter1.IDST;
length--;
break;
case pwr: //Prmter1.PWRJZ=TEMP(3);
// * P1++ = Prmter1.PWR+Prmter1.PWRJZ;
* P1++ = Prmter1.PWR;
length--;
break;
case lanalm: * P1++ = Prmter1.alm;
length--;
break;
case pwrctr: * P1++ = Prmter1.ctr;
length--;
break;
case v7: * P1++ = Prmter1.v7L;
length--;
* P1++ = Prmter1.v7H;
length--;
break;
case temp: * P1++ = Prmter1.TEMP;
length--;
break;
case pwru: * P1++ = Prmter1.PWRU;
length--;
* P1++ = 0;
length--;
break;
case ctru: * P1++ = Prmter1.CTRU;
length--;
* P1++ = 0;
length--;
break;
case v7u: * P1++ = Prmter1.v7U;
length--;
* P1++ = 0;
length--;
break;
case tempu: * P1++ = Prmter1.TEMPU;
length--;
* P1++ = 0;
length--;
break;
case idu: * P1++ = Prmter1.IDU;
length--;
* P1++ = 0;
length--;
break;
case id1: * P1++ = Prmter1.ID1;
length--;
* P1++ = 0;
length--;
break;
case poffset1: *P1++=Prmter1.POFFSET1 ;
length--;
break;
case poffset2: *P1++=Prmter1.POFFSET2 ;
length--;
break;
case ctrbb: *P1++=Prmter1.CTRBB ;
length--;
break;
// case gcu1jz: *P1++= Prmter1.GCU1JZ;
// length--;
// break;
// case gcu2jz: *P1++= Prmter1.GCU2JZ;
// length--;
// break;
default: receive_buf[9] = *--P1;
receive_buf[8] = *--P1;
erro = erro | 0x01;
length = 0;
break;//特殊处理
}
}
if(erro & 0x01)
{
length = 2;//查询参数失败
//receive_buf[4] = 0x05;
}
else
{
length = receive_buf[7];
}
return length;
}
/**********************************************************
** 功能说明: 发送参数函数
** 输入参数: 类型: uchar 应答标志位
类型: uchar 命令体的长度
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2005/01/11
*********************************************************/
void send_reply_flag(uchar reply_flag,uchar length)
{
auto uchar start,i;
receive_buf[7] = length;
receive_buf[6] = reply_flag;
start = 1; //CRC校验
length = length + 7;
CheckCRC(receive_buf,length,start,pChecksum);
receive_buf[length + 1] = pChecksum[0];
receive_buf[length + 2] = pChecksum[1];
length = length + 3;//加上校验字节(2BYTE),再加一个字节,就为包的总长度-1
receive_buf[length] = 0x4e;//最后一个字节是包尾
portd_wbuf = portd_wbuf | 0x80; //485发送使能
PORTD = portd_wbuf;
TXEN = 1; //USART 使能
delay_unit(2000);
length = length + 1;
for(i = 0;i < length;i ++)
{
if((i==0)||(i==(length-1)))
{
TXREG = receive_buf[i];
}
else if(receive_buf[i]==0x5e)
{
TXREG = 0x5e;
receive_buf[i]=0x5d;
i--;
}
else if(receive_buf[i]==0x4e)
{
TXREG = 0x5e;
receive_buf[i]=0x4d;
i--;
}
else
{
TXREG = receive_buf[i];
}
while(TRMT == 0)
{
;
}
}
delay_unit(1000);
TXEN = 0;
portd_wbuf = portd_wbuf & 0x7f;
PORTD = portd_wbuf;
headend_flag=0x00;
tran_flag=0;//转义处理标志位,1:进行了0X4E的转义处理(将0X4E转义为0X5E,0X4D);0:未进行转义处理
return;
}
/**********************************************************
** 功能说明: CRC校验函数
** 输入参数: 类型: uchar* 须校验的数组
类型: uchar 命令体的长度
类型: uchar 开始位置
类型: uchar* 校验配置表
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 李承胜 创建时间:不详
*********************************************************/
void CheckCRC(uchar *pData, uchar length,uchar start, uchar *pChecksum)
{
auto uchar i = 0;
auto uint checksum = 0;
for(i = 0;i < length;i ++)
{
checksum = ( checksum << 8) ^ CRCTable[( checksum >> 8 ) ^ pData[i + start]];
}
pChecksum[0] = checksum % 256;
pChecksum[1] = checksum / 256;
return;
}
/**********************************************************
** 功能说明: 接受数据数组的初始化
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void receive_free()
{
auto uchar i;
for(i = 0; i < BUF_LENGTH; i ++)
{
receive_buf[i] = 0;
}
}
/**********************************************************
** 功能说明: 查询温度值或频率信道号
** 输入参数: fstadr 类型:uint: 温度值首地址或频率值首地址
bytenumb 类型:uchar:占字节数,1代表占1个字节,2代表占2个字节
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2004/07/21
*********************************************************/
uchar Query_tp(uint fstadr,uchar bytenumb)
{
uchar i;
uchar length;
uchar buf;
//buf = receive_buf[9];//包序号
//length =rrom(tpdots) ;//温度或频率划分点数
buf=bytenumb*30;
for(i=0; i<buf; i++)
{
receive_buf[i+10]= rrom(fstadr+i);
}
length =buf+2;
return length;
}
/**********************************************************
** 功能说明: 查询所有温补、标称值补偿、频响补偿参数编码,编码占2个字节
** 输入参数: adsnumb 类型:uchar: =1,选择温补编码表格;=2,选择标称值补偿编码表格;=3,选择频补编码表格
bubuf 类型:uchar: 温度或标称值或频响补偿参数总数
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2005/09/5
*********************************************************/
uchar Query_csd(uchar adsnumb,uchar bubuf )
{
uchar i,buf;
uchar length;
buf = receive_buf[9];//包序号
for(i=0; i<(bubuf*2); i++)
{
dog();
if(adsnumb==1)
{
receive_buf[i+10]= prtemp[i];
}
else
{
receive_buf[i+10]= attact[i];
}
}
length =bubuf*2+2;
return length;
}
/**********************************************************
** 功能说明: 查询所有温补、标称值补偿、频响补偿参数表内容,所有补偿参数占1个字节
** 输入参数: firstadr 类型:uint: 补偿参数表的首地址
bubuf 类型:uchar: 温度或标称值或频响补偿参数总数
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2004/07/21
*********************************************************/
uchar Query_cszd(uint firstadr,uchar bubuf)
{
uchar i,buf;
uchar length;
buf = receive_buf[10];//位置
for(i=0; i<bubuf; i++)
{
dog();
receive_buf[i+11]= rrom(firstadr+i+(buf-1)*bubuf);
}
length =bubuf+3;
return length;
}
/**********************************************************
** 功能说明: 设置温度值或频率信道号
** 输入参数: fstadr 类型:uint: 温度值首地址或频率值首地址
bytenumb 类型:uchar:占字节数,1代表占1个字节,2代表占2个字节
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2005/09/05
*********************************************************/
uchar Set_tp(uint fstadr )
{
uchar i;
uchar length;
uchar *P = 0;
//uchar buf;
//erro=0;
length = receive_buf[7]-2;//命令体长度-2
//wrom(tpdots,length);//将温度点数或频率点数写入EEPROM对应地址
// buf = receive_buf[7];//包序号
P = receive_buf+10;
i=0;
while(length)
{
dog();
wrom(fstadr+i,*P++);
i++;
length--;
}
// length = receive_buf[5];
length = 2;//回应命令体为2字节
return length;
}
/**********************************************************
** 功能说明: 设置所有温补、标称值补偿、频响补偿参数表内容,所有补偿参数占1个字节
** 输入参数: firstadr 类型:uint: 补偿参数表的首地址
bubuf 类型:uchar: 温度或标称值或频响补偿参数总数
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2004/07/21
*********************************************************/
uchar Set_cszd(uint firstadr,uchar bubuf)
{
uchar i,buf;
uchar length;
uchar *P = 0;
//erro=0;
length = receive_buf[7]-3;
buf = receive_buf[10];//位置
P = receive_buf+11;
i=0;
while(length)
{
dog();
wrom(firstadr+(buf-1)*bubuf+i,*P++);
i++;
length--;
}
// length = receive_buf[5];
length = 2;
return length;
}
/**********************************************************
** 功能说明: 中断处理子程序(包括接收中断、定时器中断)
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2005/12/27
*********************************************************/
void interrupt int_process(void)
{
auto uchar i;
// uchar buf;
if(RCIF == 1) //USART接收中断标志位为1
{
if(portd_wbuf&0x80)//如果处于发送状态,返回主程序,不处理缓冲区中的数据
{
return;
}
if(receive_over == 1 )//如果接收完成标志为1,则接收完成,不再接收数据.
{
return;
}
if(receive_cnt > 79)//接收缓冲超过80个字节时,就为溢出,将接收缓冲重新计数
{
receive_time_on = 0;//接收超时定时器开关关闭
receive_time_count = 0;//接收超时定时计数器清零
receive_cnt = 0;//发送或接收的字节数清零.
for(i = 0; i < BUF_LENGTH; i++) //将接收缓冲清零
{
receive_buf[i] = 0;
}
return;
}
receive_buf[receive_cnt] = RCREG;
// if (receive_cnt==1)
// {
// buf=receive_buf[receive_cnt];
// }
if(receive_buf[receive_cnt] == 0x4E)//接收到的字节是包头或包尾
{
if(headend_flag==0x01)//判断接收到的是包头还是包尾,如果标志=1,则接收到过包头,现在接收到的是包尾;
{
headend_flag=0x02;//接收到的是包尾
}
if(headend_flag==0x00)//判断接收到的是包头还是包尾,如果标志=0,则接收到的是包头,之前没接收到包尾和包头;
{
receive_buf[0]=0x4E;
headend_flag=0x01;//接收到的是包头
receive_cnt = 0x01;//接收的字节数为1个.
receive_time_on = 0x01;//接收超时定时器开关打开
receive_time_count = 0x00;//接收超时定时计数器清零
// for(i = 0; i < BUF_LENGTH;i++)//将接收缓冲清零
// {
// receive_buf[i] = 0;
// }
return;
}
}
else if(receive_buf[0] != 0x4E)//如果缓冲区接收到的第一个字节不是包头
{
receive_cnt = 0x00;//发送或接收的字节数清零.
receive_time_on = 0x00;//接收超时定时器开关关闭
receive_time_count = 0x00;//接收超时定时计数器清零
return;
}
if((receive_buf[receive_cnt-1] == 0x5E)&&(tran_flag==0x00))//接收到转义字节0x5E
{
// tran_flag=0x01;
if (receive_buf[receive_cnt] == 0x4D)//0X5E的转义处理
{
receive_buf[receive_cnt-1] =0X4E;
tran_flag=0x01;//完成转义处理
//receive_cnt--;
return;
}
else if(receive_buf[receive_cnt]==0x5D)//0X5E的转义处理
{
tran_flag=0x01;//完成转义处理
receive_buf[receive_cnt-1]=0x5E;
//receive_cnt--;
return;
}
else //说明接收错误,返回
{
tran_flag=0x00;
headend_flag=0x00;
receive_time_on = 0;//接收超时定时器开关关闭
receive_time_count = 0;//接收超时定时计数器清零
receive_cnt = 0;//发送或接收的字节数清零.
return;
}
}
receive_cnt++;
if(headend_flag==0x02)//接收到了包头和包尾,并且没有接收到转义字节0X5E或转义处理已完成
{
tran_flag=0x00;
headend_flag==0x00;//包头包尾标志清零
receive_time_on = 0;//接收超时定时器开关关闭
receive_time_count = 0;//接收超时定时计数器清零
receive_over = 1;//接收完成标志置1
RCIE = 0;//接收允许标志位清零,不允许接收
CREN = 0;
return;
}
}
else if(TMR1IF == 1)
{
chushi++;
// if (chushi<=0x0d6b)
// {
TMR1IF=0;
// }
return;
}
else if(TMR2IF == 1)
{
// i= 100;
TMR2IF =0;
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -