📄 sensor.c
字号:
#include <iom128v.h>
#include <Sensor.h>
#include <Control.h>
/*#define BUS_ADD1 0X5A
#define BUS_ADD2_T1 0X92
#define BUS_ADD2_T2 0X90*/
extern unsigned char vol1_high;
extern unsigned char vol1_low;
extern unsigned char vol2_high;
extern unsigned char vol2_low;
extern unsigned char vol3_high;
extern unsigned char vol3_low;
extern unsigned char vcc_high;
extern unsigned char vcc_low;
extern unsigned char temp_alarm[3],temp_alarm1[3];
extern unsigned char temperature_h[2],temperature_l[2];
extern unsigned char temperature_alarm;
//---------------------------------------------------------
// NAME: sensor_init()
// ENTRY: sens
// RETURN: void
// FUNCTION: init the sensor chip
// MODIFY: 2004.2.3
//--------------------------------------------------------
void sensor_init(unsigned char sens)
{
i2c_Write(0x03,0x40,sens,0);
i2c_Write(0xef,0x43,sens,0);
i2c_Write(0x2d,0x4a,sens,0);
}
//---------------------------------------------------------
// NAME: CHECK_CHIP()
// ENTRY: sens
// RETURN: void
// FUNCTION: Read the chip ID
// MODIFY: 2004.2.3
//--------------------------------------------------------
unsigned char CHECK_CHIP(unsigned char sens )
{
unsigned char temp1[1],temp2[1];
i2c_Read(&temp1[0], WIN_ID_L,sens,0 );
i2c_Read(&temp2[0], WIN_ID_H ,sens,0);
if((temp1[0]==0XA3)&&(temp2[0]==0X5C))
return 1;
else
return 0;
}
//---------------------------------------------------------
// NAME: voltage_disp()
// ENTRY: sens1
// RETURN: void
// FUNCTION: disply the voltage status
// MODIFY: 2004.2.3
//--------------------------------------------------------
void voltage_disp(unsigned char sens1)
{
if(! CHECK_CHIP(sens1))
{
LCD_CLR();
disp_voltage_trl(sens1);
spk_alarm();
}
else
SHOW_LOGO(sens1 + 49);
}
//---------------------------------------------------------
// NAME: voltage_check()
// ENTRY: sens
// RETURN: void
// FUNCTION: Check the voltage
// MODIFY: 2004.2.3
//--------------------------------------------------------
void voltage_check(unsigned char sens)
{
unsigned char vol[1],vol3[3],vcc[3],vol_flg[4];
if(! CHECK_CHIP(sens)) return;
/*
{
LCD_CLR();
disp_voltage_trl(sens);
spk_alarm();
}
*/
/*
vol=0;
vol=i2c_Read( 0X20 ,sens,0);
//vol=i2c_Read( VIN1 ,sens+1,0);
vol1[2]=vol1[1];vol1[1]=vol1[0];vol1[0]=vol;
if((vol1[0] > vol1_high)&&(vol1[1]>vol1_high)&&(vol1[2]>vol1_high))
vol_flg[0]=0x11;
if((vol1[0]<vol1_low)&&(vol1[1]<vol1_low)&&(vol1[2]<vol1_low))
vol_flg[0]=0x10;
vol=0;
vol=i2c_Read( 0X22 ,sens,0);
//vol=i2c_Read( VIN2 ,sens+1,0);
vol2[2]=vol2[1];vol2[1]=vol2[0];vol2[0]=vol;
if((vol2[0]>vol2_high)&&(vol2[1]>vol2_high)&&(vol2[2]>vol2_high))
vol_flg[1]=0x21;
if((vol2[0]<vol2_low)&&(vol2[1]<vol2_low)&&(vol2[2]<vol2_low))
vol_flg[1]=0x20;
*/
i2c_Read(&vol[0], 0X21,sens,0 );
//vol=i2c_Read( VIN3,sens+1,0 );
vol3[2]=vol3[1];
vol3[1]=vol3[0];
vol3[0]=vol[0];
if((vol3[0]>vol3_high)&&(vol3[1]>vol3_high)&&(vol3[2]>vol3_high))
vol_flg[2]=0x31;
if((vol3[0]<vol3_low)&&(vol3[1]<vol3_low)&&(vol3[2]<vol3_low))
vol_flg[2]=0x30;
i2c_Read(&vol[0], 0X23,sens,0 );
//vol=i2c_Read( VCC,sens+1,0 );
vcc[2]=vcc[1];
vcc[1]=vcc[0];
vcc[0]=vol[0];
if((vcc[0]>vcc_high)&&(vcc[1]>vcc_high)&&(vcc[2]>vcc_high))
vol_flg[3]=0x41;
if((vcc[0]<vcc_low)&&(vcc[1]<vcc_low)&&(vcc[2]<vcc_low))
vol_flg[3]=0x40;
/*if((vol_flg[0]==0x11)||(vol_flg[1]==0x21)||(vol_flg[2]==0x31)||(vol_flg[3]==0x41))
//disp_VOL_trl( );
else
if((vol_flg[0]==0x11)||(vol_flg[1]==0x21)||(vol_flg[2]==0x31)||(vol_flg[3]==0x41))
// disp_VOL_trl( );*/
}
//---------------------------------------------------------
// NAME: temp_check()
// ENTRY: sens
// RETURN: void
// FUNCTION:temperature check and control the fan
// MODIFY: 2004.2.3
//--------------------------------------------------------
void temp_check( unsigned char sens )
{
unsigned char tep1[1],tep2[1],dat;
unsigned char alarm;
dat=0;
alarm=0;
//read the temperature
i2c_Read(&tep1[0], 0X27,sens ,0);
tep1[0] = tep1[0] - 6;
i2c_Read(&tep2[0], 0X27,sens + 1,0);
tep2[0] = tep2[0] - 6;
temp_alarm[0]= temp_alarm[1];
temp_alarm[1]= temp_alarm[2];
temp_alarm[2]=tep1[0];
temp_alarm1[0]= temp_alarm1[1];
temp_alarm1[1]= temp_alarm1[2];
temp_alarm1[2]= tep2[0];
if(( temperature_h[0]<temp_alarm[0])&&( temperature_h[0]<temp_alarm[1])&&( temperature_h[0]<temp_alarm[2]))
{
i2c_Write(0xff,FAN1_DCSR,sens,0);
i2c_Write(0xff,FAN2_DCSR,sens,0);
alarm=1;
temperature_alarm=1;
}
else
{
alarm=0;
temperature_alarm=0;
i2c_Write(0x55,FAN1_DCSR,sens,0);
i2c_Write(0x55,FAN2_DCSR,sens,0);
}
if(( temperature_h[1]<temp_alarm1[0])&&( temperature_h[1]<temp_alarm1[1])&&( temperature_h[0]<temp_alarm[2]))
{
i2c_Write(0xff,FAN1_DCSR,sens,0);
i2c_Write(0xff,FAN2_DCSR,sens,0);
alarm=1;
temperature_alarm=1;
}
else
{
alarm=0;
temperature_alarm=0;
i2c_Write(0x55,FAN1_DCSR,sens,0);
i2c_Write(0x55,FAN2_DCSR,sens,0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -