📄 cdma800.c
字号:
** 功能说明: adc5308芯片输出处理
** 输入参数: addr 类型:uchar :芯片的管道号
buf 类型:uchar :输出数据
** 输出参数:
** 返 回 值: 无
** 引用函数:
***********************************************************/
//void DAC(uchar addr,uchar buf)
//{
// union buf_union dabuf1;
// union buf_union dabuf2;
// int k;
// SSPSTAT = 0x00;
// SSPCON = 0x21;
// addr = addr & 0x07;
// dabuf1.buf2[1] = addr;
// dabuf1.buf2[0] = buf;
// dabuf2.buf1 = 0x8003;
// portc_wbuf = portc_wbuf & 0xfb;
// PORTC=portc_wbuf;
// SSPIF = 0;
// for(k=1;k>=0;k--)
// {
// SSPBUF = dabuf2.buf2[k];
// while(SSPIF == 0)
// {
// ;
// }
// SSPIF = 0;
// }
// portc_wbuf = portc_wbuf | 0x04;
// PORTC = portc_wbuf;
// dabuf1.buf1 = dabuf1.buf1 << 4;
// portc_wbuf = portc_wbuf & 0xfb;
// PORTC=portc_wbuf;
// SSPIF = 0;
// for(k=1;k>=0;k--)
// {
// SSPBUF = dabuf1.buf2[k];
// while(SSPIF == 0)
// {
// ;
// }
// SSPIF = 0;
// }
// portc_wbuf = portc_wbuf | 0x04;
// PORTC = portc_wbuf;
//}
/**********************************************************
** 功能说明: adc5314芯片处理,10位精度
** 输入参数: addr 类型:uchar :adc5314选用的管道号
buf8 类型:uchar :输入数据
** 输出参数:
** 返回值: 无
** 引用函数:
***********************************************************/
void DAC(uchar addr,uchar dac_H,uchar dac_L)
{
union buf_union dabuf1;
union buf_union dabuf3;
int k;
dog();
TRISC3 = 0;
TRISC5 = 0;
TRISC2 = 0;
dabuf3.buf2[1]=dac_H;
dabuf3.buf2[0]=dac_L;
// if (dabuf3.buf1>=0x0396)//电压不要超过4.5V
// {
// dac_H=0x03;
// dac_L=0x30;
// }
SSPSTAT = 0x40;
SSPCON = 0x21;
addr = addr <<2;
addr = addr|0x02;
dabuf1.buf2[1] = addr;
dac_H=dac_H<<6;
dabuf1.buf2[0] = dac_H | (dac_L>>2);
dac_L=(dac_L<<2)&0x0f;//取值的低2位
dabuf1.buf1= (dabuf1.buf1 << 4)|dac_L;
portc_wbuf = portc_wbuf | 0x04;
PORTC=portc_wbuf;
portc_wbuf = portc_wbuf & 0xfb;
PORTC=portc_wbuf;
SSPIF = 0;
for(k=1;k>=0;k--)
{
SSPBUF = dabuf1.buf2[k];
while(SSPIF == 0)
{
;
}
SSPIF = 0;
}
portc_wbuf = portc_wbuf | 0x04;
PORTC=portc_wbuf;
}
/**********************************************************
** 功能说明: 温度检测函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
*********************************************************/
void CHECK_TEMP()
{
uchar TEMP_adc;
uchar buf;
uchar buff;
TEMP_adc=adc_read(0);
temp_cnt++;
tempbuf=tempbuf+TEMP_adc;
if(temp_cnt>=TEMP_CNT)
{
tempbuf=tempbuf/temp_cnt;//取平均值
Prmter1.TEMPU_L =tempbuf & 0x00ff;
Prmter1.TEMPU_H= 0;
temp_cnt = 0x00;
tempbuf= 0x0000;
Prmter1.TEMP= (100*Prmter1.TEMPU_L)/51-60;
buf=tempinit-Prmter1.TEMP;
buff=-4;
if(tempcheck==0)
{
tempinit=Prmter1.TEMP;
tempcheck=1;
init_sign_ctl();
}
else if(tempcheck==1)
{
if((buf>4)&&(buf<0x80))
{
tempinit=Prmter1.TEMP;
init_sign_ctl();
}
else if((buf<buff)&&(buf>0x80))
{
tempinit=Prmter1.TEMP;
init_sign_ctl();
}
}
}
return;
}
/**********************************************************
** 功能说明: 输出过功率检测函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
*********************************************************/
void CHECK_CTR()
{
uchar buff;
buff = adc_read(4);
Prmter1.CTRU=buff;
Prmter1.CTR=buff;
if (buff>=204)//大于4V是不过功率
{
Prmter1.F_PWR=0;
}
else//小于2.5V是过功率告警
{
Prmter1.F_PWR=1;
}
}
/**********************************************************
** 功能说明: 输出功率检测函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
**********************************************************/
void CHECK_POF()
{
Prmter1.POFU_L = adc_read(1);
Prmter1.POFU_H =0;
Prmter1.POF =Prmter1.POFU_L*20/51-19;
}
/**********************************************************
** 功能说明: 反向输出功率检测函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
***********************************************************/
void CHECK_POR()
{
Prmter1.PORU_L = adc_read(2);
Prmter1.PORU_H = 0;
Prmter1.POR =Prmter1.PORU_L*20/51-19;
}
/**********************************************************
** 功能说明: 28V检测函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
**********************************************************/
void CHECK_v28v()
{
union buf_union V28BUF;
Prmter1.V28U_L = adc_read(3);
Prmter1.V28U_H = 0;
V28BUF.buf1=Prmter1.V28U_L *63/5;
Prmter1.V28_L = V28BUF.buf2[0];
Prmter1.V28_H = V28BUF.buf2[1];
}
/**********************************************************
** 功能说明: 电流检测函数id1
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
**********************************************************/
void CHECK_ID1()
{
uchar ID_adc;
ID_adc=adc_read(5);
id1_cnt++;
idbuf1=idbuf1+ID_adc;
if(id1_cnt>=ID_CNT)
{
idbuf1=idbuf1/id1_cnt;
Prmter1.ID1U_L =idbuf1 & 0x00ff;
id1_cnt = 0x00;
idbuf1= 0x0000;
Prmter1.ID1 =Prmter1.ID1U_L;
// if (((Prmter1.ID1U_L>20)&&(Prmter1.ID1U_L<41))&&((Prmter1.ID2U_L>20)&&(Prmter1.ID2U_L<113))&& if ((Prmter1.ID3U_L>20)&&(Prmter1.ID3U_L<113)))
// {
// Prmter1.ID3ST=0;
// }
// else
// {
// Prmter1.ID3ST=1;
// }
}
}
/**********************************************************
** 功能说明: 电流检测函数id2
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
**********************************************************/
void CHECK_ID2()
{
uchar ID_adc;
ID_adc=adc_read(7);
id2_cnt++;
idbuf2=idbuf2+ID_adc;
if(id2_cnt>=ID_CNT)
{
idbuf2=idbuf2/id2_cnt;
Prmter1.ID2U_L =idbuf2 & 0x00ff;
id2_cnt = 0x00;
idbuf2= 0x0000;
Prmter1.ID2 = Prmter1.ID2U_L;
// if ((Prmter1.ID2U_L>20)&&(Prmter1.ID2U_L<113))
// {
// Prmter1.ID2ST=0;
// }
// else
// {
// Prmter1.ID2ST=1;
// }
}
}
/**********************************************************
** 功能说明: 电流检测函数id3
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
**********************************************************/
void CHECK_ID3()
{
uchar ID_adc;
uchar buf1;
uchar buf2;
uchar buf3;
ID_adc=adc_read(6);
id3_cnt++;
idbuf3=idbuf3+ID_adc;
if(id3_cnt>=ID_CNT)
{
idbuf3=idbuf3/id3_cnt;
Prmter1.ID3U_L =idbuf3 & 0x00ff;
id3_cnt = 0x00;
idbuf3= 0x0000;
Prmter1.ID3 = Prmter1.ID3U_L;
if ((Prmter1.ID1U_L>7)&&(Prmter1.ID1U_L<41))//0.15V~0.8V
{
buf1=0;
}
else
{
buf1=1;
}
if ((Prmter1.ID2U_L>7)&&(Prmter1.ID2U_L<128))//0.15V~2.5V
{
buf2=0;
}
else
{
buf2=1;
}
if ((Prmter1.ID3U_L>7)&&(Prmter1.ID3U_L<128))//0.15V~2.5V
{
buf3=0;
}
else
{
buf3=1;
}
buf3=buf1+buf2+buf3;
if(buf3==0x00)
{
Prmter1.ID1ST=0;
}
else
{
Prmter1.ID1ST=1;
}
}
}
/**********************************************************
** 功能说明: 485串口数据处理
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
**********************************************************/
void serial_data()
{
auto uchar start,length,buf,buf1;
uchar bufver;//接收到的版本号
if(receive_over == 1)//如果接收完毕(包头,包尾都收到)
{
length = receive_cnt - 2;
//if(Prmter1.TYPE != receive_buf[1]) //判断协议类型
// if(TYPE != receive_buf[1]) //判断协议类型
// {
// send_reply_flag(0x10,0x00);//协议类型错误
// goto go_return;
// }
if((Prmter1.ADDR != receive_buf[4]) && (receive_buf[4] != 0xff))//模块地址错(0xff为广播群发)0X00为没有设置地址
{
goto go_return; //模块地址不符合,没返回
}
dog();
bufver=receive_buf[2] & 0x0f;//取缓冲数组的第二个字节的低4位字节,高4位是信息来源
if(bufver!= PROTL)//协议版本号判断
{
send_reply_flag(0x02,0x00);//0X02表示版本错误
goto go_return;
}
// if(receive_buf[7] > 69) //命令体长度不能大于69
// {
// send_reply_flag(0x05,0x00);
// goto go_return;
// }
if(receive_buf[6]!= 0xff) //命令头应答标志错
{
send_reply_flag(0x06,0x00);
goto go_return;
}
length =receive_cnt-4; //长度=命令体长度+……(不包括起始、结束、ASCII校验这4个字节)
//length = receive_buf[7] + 7; //长度=命令体长度+……(不包括起始、结束、ASCII校验这4个字节)
start = 1;
CheckCRC(receive_buf,length,start,pChecksum);
buf1 = length + 1;
if((pChecksum[0] != receive_buf[buf1]) || (pChecksum[1] != receive_buf[buf1+1]))//CRC检验判断
{
send_reply_flag(0x03,0x00);
goto go_return;
}
if(receive_buf[5] == 0x40)//查询基本参数
{
buf = Set_Basic_Parameter();//模块基本信息参数查询
if(erro&0x01)//查询出错
{
receive_buf[6] = 0x08;
erro = erro & 0xfe;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
if(receive_buf[5] == 0x60)//设置基本信息项
{
buf = Set_Basic_Parameter();//模块基本信息参数设置
if(erro&0x02)//设置出错
{
receive_buf[6] = 0x07;
erro = erro & 0xfd;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
if(receive_buf[5] == 0xc1)//设置参数
{
buf = Set_Parameter();//设置参数
if(erro&0x02)//设置出错
{
receive_buf[6] = 0x07;
erro = erro & 0xfd;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
else if(receive_buf[5] == 0xc2)//查询参数
{
buf =Set_Parameter();
if(erro&0x01)//查询出错
{
receive_buf[6] = 0x08;
erro = erro & 0xfe;
}
else
{
receive_buf[6] = 0x00;
}
send_reply_flag(receive_buf[6],buf);
goto go_return;
}
else if(receive_buf[5] == 0x50)//查询模块参数地址
{
buf = Query_Address();
send_reply_flag(0x00,buf);
goto go_return;
}
else if(receive_buf[5]==0xd1)//查询表格参数
{
if (receive_buf[8]==0x01)//查询所有温度值
{
buf=Query_tp(tempd,0x01);
}
else if (receive_buf[8]==0x02)//查询所有频率值
{
buf=Query_tp(freqd,0x02);
}
else if (receive_buf[8]==0x03)//查询所有温补参数编码
{
buf=Query_csd(1,tn);
}
else if (receive_buf[8]==0x04)//查询所有频补参数编码
{
buf=Query_csd(2,pn);
}
else if (receive_buf[8]==0x05)//查询所有标称值参数编码
{
buf=Query_csd(3,zyn);
}
else if (receive_buf[8]==0x06)//查询所有温补参数表内容
{
buf=Query_cszd(tempcszd,tn);
}
else if (receive_buf[8]==0x07)//查询所有频补参数表内容
{
buf=Query_cszd(freqcszd,pn);
}
else if (receive_buf[8]==0x08)//查询所有标称值参数表内容
{
buf=Query_cszd(bczcszd,zyn);
}
receive_buf[7]=buf;//命令体长度
send_reply_flag(0x00,buf);
goto go_return;
}
else if(receive_buf[5]==0xd2)//设置表格参数
{
if (receive_buf[8]==0x01)//设置所有温度值
{
buf=Set_tp(tempd);
}
else if (receive_buf[8]==0x02)//设置所有频率值
{
buf=Set_tp(freqd);
}
else if (receive_buf[8]==0x06)//设置所有温补参数表内容
{
buf =Set_cszd(tempcszd,tn);
}
else if (receive_buf[8]==0x07)//设置所有频补参数表内容
{
buf =Set_cszd(freqcszd,pn);
}
else if (receive_buf[8]==0x08)//设置所有标称值参数表内容
{
buf =Set_cszd(bczcszd,zyn);
}
receive_buf[7]=buf;//命令体长度
send_reply_flag(0x00,buf);
goto go_return;
}
else
{
send_reply_flag(0x09,0x00); //命令编号错
goto go_return;
}
}
else if(receive_over == 0 && receive_time_on == 1)
{
if(receive_time_count >= 200)
{
headend_flag=0x00;
tran_flag=0x00;
receive_time_on = 0;
receive_time_count = 0;
receive_free();
receive_cnt = 0x00;
CREN = 1;
RCIE = 1;
return;
}
else
{
receive_time_count++;
return;
}
}
// T1CON=0x31;
return;
go_return:
headend_flag=0x00;
tran_flag=0x00;
receive_free();
receive_over = 0;
receive_cnt = 0;
CREN = 1;
RCIE = 1;
// T1CON=0x31;
return;
}
/**********************************************************
** 功能说明: 基本信息参数设置/查询函数
** 输入参数: 无
** 输出参数:
** 返 回 值: 参数个数
** 引用函数:
**********************************************************/
uchar Set_Basic_Parameter()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -