📄 lna3.c.bak
字号:
void CHECK_temp()
{
// uchar buf;
// uchar buff;
// Prmter1.TEMPU = adc_read(2);
// Prmter1.TEMP= (100*Prmter1.TEMPU)/51-60;
// buf=tempinit-Prmter1.TEMP;
// buff=-4;
// if(tempcheck==0)
// {
// tempinit=Prmter1.TEMP;
// tempcheck=1;
// }
// else if(tempcheck==1)
// {
// if(buf>4)
// {
// tempinit=Prmter1.TEMP;
// init_sign_ctl();
// }
// else if((buf<buff)&&(buf>0x80))
// {
// tempinit=Prmter1.TEMP;
// init_sign_ctl();
// }
// }
//
// return;
uchar TEMP_adc;
uchar buf;
uchar buff;
TEMP_adc=adc_read(2);
temp_cnt++;
tempbuf=tempbuf+TEMP_adc;
if(temp_cnt>=TEMP_CNT)
{
tempbuf=tempbuf/temp_cnt;//取平均值
Prmter1.TEMPU =tempbuf & 0x00ff;
temp_cnt = 0x00;
tempbuf= 0x0000;
Prmter1.TEMP= (100*Prmter1.TEMPU)/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;
}
/**********************************************************
** 功能说明: 电流检测
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2005/06/06
***********************************************************/
void CHECK_id()
{
uchar ID_adc;
//uchar buf;
ID_adc=adc_read(4);
//ID_adc=adc_read(4);
id_cnt++;
idbuf=idbuf+ID_adc;
if(id_cnt>=ID_CNT)
{
idbuf=idbuf/id_cnt;//取平均值
Prmter1.IDU =idbuf & 0x00ff;
id_cnt = 0x00;
idbuf= 0x0000;
Prmter1.ID1 =Prmter1.IDU;
if ((Prmter1.IDU>140)&&(Prmter1.IDU<225)) //2。8V~4。4V为正常
{
Prmter1.IDST=0;
}
else
{
Prmter1.IDST=1;
}
}
}
/**********************************************************
** 功能说明: 对sda端口进行赋值
** 输入参数: buf 类型:uchar :0或1
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void sda(uchar buf)
{
if(buf)
{
portc_wbuf = portc_wbuf | 0x02;
PORTC = portc_wbuf;
}
else
{
portc_wbuf = portc_wbuf & 0xfd;
PORTC = portc_wbuf;
}
}
/**********************************************************
** 功能说明: 对scl端口进行赋值
** 输入参数: buf 类型:uchar :0或1
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void scl(uchar buf)
{
if(buf)
{
portc_wbuf = portc_wbuf | 0x01;
PORTC = portc_wbuf;
}
else
{
portc_wbuf = portc_wbuf & 0xfe;
PORTC = portc_wbuf;
}
}
/**********************************************************
** 功能说明: 读eeprom的值
** 输入参数: addr 类型:uint :读数的地址
** 输出参数: buf 类型:uchar :读出的数据
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
uchar rrom(uint addr)
{
uchar buf;
union buf_union comm;
dog();
T1CON=0x00;
RCIE=0;
CREN=0;
comm.buf1 = addr;
_nop();
iic_stop();
iic_star();
iic_send((comm.buf2[1] <<1)| 0xa0);
iic_ack();
iic_send(comm.buf2[0]);
iic_ack();
iic_star();
iic_send((comm.buf2[1] <<1)|0xa1);
iic_ack();
buf = iic_get();
iic_stop();
T1CON=0x31;
CREN=1;
RCIE=1;
return buf;
}
/**********************************************************
** 功能说明: 写eeprom
** 输入参数: addr 类型:uchar :写数据的地址
buf 类型:uchar :读出的数据
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void wrom(uint addr,uchar buf)
{
uchar ubuf;
uchar wcount;
union buf_union comm;
dog();
T1CON=0x00;
RCIE=0;
CREN=0;
wcount = 0;
comm.buf1 = addr;
iic_write_re:
if( wcount > 4 )
{
iic_stop();
_nop();
wcount = 0;
err_eeprom = 1;
T1CON=0x31;
CREN=1;
RCIE=1;
return ;
}
_nop();
iic_star();
iic_send((comm.buf2[1]<<1) | 0xa0);
ubuf = iic_ack();
if(ubuf)
{
wcount++;
_nop();
goto iic_write_re;
}
iic_send(comm.buf2[0]);
ubuf = iic_ack();
if(ubuf)
{
wcount++;
_nop();
goto iic_write_re;
}
iic_send(buf);
ubuf = iic_ack();
if(ubuf)
{
wcount++;
_nop();
goto iic_write_re;
}
iic_stop();
T1CON=0x31;
CREN=1;
RCIE=1;
return ;
}
/**********************************************************
** 功能说明: 延时函数
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void iic_delay()
{
uchar a;
for(a = 0; a < IIC_DELAY ; a++ )
{
asm("NOP");
}
}
/**********************************************************
** 功能说明: 操作eeprom时发起始命令
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void iic_star()
{
TRISC0 = 0;
TRISC1 = 0;
scl(1);
sda(1);
// _nop();
sda(0);
scl(0);
_nop();
return;
}
/**********************************************************
** 功能说明: 操作eeprom完成时发结束命令
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void iic_stop()
{
TRISC0 = 0;
TRISC1 = 0;
sda(0);
scl(1);
_nop();
sda(1);
_nop();
scl(1);
_nop();
return;
}
/**********************************************************
** 功能说明: 发数据给eeprom
** 输入参数: buf 类型:uchar :需要发送的数据
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void iic_send(uchar buf)
{
uchar i;
TRISC0 = 0;
TRISC1 = 0;
for(i = 0 ; i < 8 ;i++)
{
if( buf & 0x80 )
{
sda(1);
}
else
{
sda(0);
}
_nop();
scl(1);
//_nop();
scl(0);
//_nop();
buf = buf << 1;
}
return;
}
/**********************************************************
** 功能说明: 从eeprom获取数据
** 输入参数:
** 输出参数: buf 类型:uchar :获取的数据
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
uchar iic_get()
{
uchar i,buf;
buf = 0x00;
TRISC0 = 0;
TRISC1 = 1;
for(i = 0 ; i < 8 ;i++)
{
scl(1);
_nop();
buf = buf <<1;
if(PORTC & 0x02)
{
buf = buf|0x01;
}
scl(0);
_nop();
}
return buf;
}
/**********************************************************
** 功能说明: eeprom回应命令体
** 输入参数: buf 类型:uchar :0响应/1无响应
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
uchar iic_ack()
{
uchar buf;
TRISC1 = 1;
TRISC0 = 0;
sda(1);
_nop();
scl(1);
if(PORTC & 0x02)
buf = 1;
else
buf = 0;
scl(0);
_nop();
TRISC1 = 0;
_nop();
return buf;
}
/**********************************************************
** 功能说明: 收到数据发出响应
** 输入参数:
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 汤勇 创建时间:2004-11-16
***********************************************************/
void ack_iic(uchar buf)
{
if(buf == 0)
{
sda(0);
}
else
{
sda(1);
}
_nop();
scl(1);
_nop();
scl(0);
_nop();
return;
}
/**********************************************************
** 功能说明: 485串口数据处理
** 输入参数: 无
** 输出参数:
** 返 回 值: 无
** 引用函数:
** 创 建 人: 陈璐 创建时间:2006/01/04
*********************************************************/
void serial_data()
{
auto uchar start,length,buf,buf1;
// uchar mokuaiadd;
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_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 = Query_Basic_Parameter();//模块基本信息参数查询
send_reply_flag(0x00,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 = Query_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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -