SHT75_SDA=1;
SHT75_SCK=0; //Initial state
for(i=0;i<9;i++){ //9 SHT75_SCK cycles
SHT75_SCK=1;
SHT75_SCK=0;
}
SHT75_transstart(); //transmission start
}
/*--------------------------------------
;模块名称:SHT75_write_byte();
;功 能:DHT90写函数
;占用资源:--
;参数说明:--
;创建日期:2008.08.15
;版 本:FV1.0(函数版本Function Version)
;修改日期:--
;修改说明:--
;-------------------------------------*/
char SHT75_write_byte(unsigned char value){
//----------------------------------------------------------------------------------
// writes a byte on the Sensibus and checks the acknowledge
unsigned char i,error=0;
for (i=0;i<8;i++){ //shift bit for masking
if (0x80 & value) SHT75_SDA=1; //masking value with i , write to SENSI-BUS
else SHT75_SDA=0;
SHT75_SCK=1; //clk for SENSI-BUS
value <<=1;
// NOP_1uS();NOP_1uS(); //pulswith approx. 3 us
SHT75_SCK=0;
}
SHT75_SDA=1; //release SHT75_SDA-line
SHT75_SCK=1; //clk #9 for ack
TRISIO0 =1;
NOP_1uS(); //pulswith approx. 3 us
error = SHT75_SDA; //check ack (SHT75_SDA will be pulled down by DHT90),SHT75_SDA在第9个上升沿将被DHT90自动下拉为低电平。
TRISIO0 =0;
NOP_1uS();NOP_1uS();NOP_1uS();
SHT75_SCK=0;
SHT75_SDA=1; //release SHT75_SDA-line
return error; //error=1 in case of no acknowledge //返回:0成功,1失败
}
/*--------------------------------------
;模块名称:SHT75_read_byte();
;功 能:DHT90读函数
;占用资源:--
;参数说明:--
;创建日期:2008.08.15
;版 本:FV1.0(函数版本Function Version)
;修改日期:--
;修改说明:--
;-------------------------------------*/
char SHT75_read_byte(unsigned char ack){
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
unsigned char i,val;
SHT75_SDA=1;
val=0; //release SHT75_SDA-line
TRISIO0 =1;
for (i=0;i<8;i++){ //shift bit for masking
val<<=1;
SHT75_SCK=1; //clk for SENSI-BUS
if (SHT75_SDA) val++; //read bit
NOP_1uS();NOP_1uS();NOP_1uS(); //pulswith approx. 3 us
SHT75_SCK=0;
} //**********************************************************************
TRISIO0 =0;
if(ack) SHT75_SDA=0; //in case of "ack==1" pull down SHT75_SDA-Line
else SHT75_SDA=1; //如果是校验(ack==0),读取完后结束通讯
NOP_1uS();NOP_1uS();NOP_1uS(); //pulswith approx. 3 us
SHT75_SCK=1; //clk #9 for ack
NOP_1uS();NOP_1uS();NOP_1uS(); //pulswith approx. 3 us
SHT75_SCK=0;
NOP_1uS();NOP_1uS();NOP_1uS(); //pulswith approx. 3 us
SHT75_SDA=1; //release SHT75_SDA-line
return val;
}
//----------------------------------------------------------------------------------
char SHT75_softreset(void){
//----------------------------------------------------------------------------------
// resets the sensor by a softreset
unsigned char error=0;
SHT75_connectionreset(); //reset communication
error+=SHT75_write_byte(RESET); //send RESET-command to sensor
return error; //error=1 in case of no response form the sensor
}
/*--------------------------------------
;模块名称:SHT75_measure();
;功 能:测量温湿度函数
;占用资源:--
;参数说明:--
;创建日期:2008.08.15
;版 本:FV1.0(函数版本Function Version)
;修改日期:--
;修改说明:--
;-------------------------------------*/
char SHT75_measure(unsigned char *p_value,unsigned char mode){
// makes a measurement (humidity/temperature) with checksum
unsigned char error;
unsigned int i;
SHT75_transstart(); //transmission start
error =SHT75_write_byte(mode);
//************************************************************
TRISIO0 =1;
for (i=0;i<65535;i++){
CLRWDT();
if(SHT75_SDA==0) break; //wait until sensor has finished the measurement
}
if(SHT75_SDA) error +=1; // or timeout (~2 sec.) is reached
TRISIO0 =0;
*(p_value) = SHT75_read_byte(ACK); //read the first byte (MSB)
*(p_value+1) = SHT75_read_byte(ACK); //read the second byte (LSB)
SHT75_read_byte(noACK); //read checksum
return error;
}
/*******************************************************************************
函数说明;经过温度校准的湿度获取函数
输入数据:温度(X10^2)
输出数据:校准后湿度(X10^7)
特殊说明:为了避免浮点数的计算 采用将湿度放大X10^7 这样的计算都是整数
返回的湿度放大了10倍!!
*******************************************************************************/
unsigned int GetRH(unsigned int hum1,unsigned int temper){
const unsigned long c1=40000000,c2=405000,c3=28;
unsigned long hum;