delay_little();
SCK_1;
delay_little();
return val;
}
//***************************************************
//温湿度的计算和修正
//************************************************
void calc_sth11(float *p_humidity ,float *p_temperature)
{
const float C1=-4.0; // for 12 Bit
const float C2=+0.0405; // for 12 Bit
const float C3=-0.0000028; // for 12 Bit
const float T1=+0.01; // for 14 Bit @ 5V
const float T2=+0.00008; // for 14 Bit @ 5V
float rh=*p_humidity; // rh: Humidity [Ticks] 12 Bit
float t=*p_temperature; // t: Temperature [Ticks] 14 Bit
float rh_lin; // rh_lin: Humidity linear
float rh_true; // rh_true: Temperature compensated humidity
float t_C; // t_C : Temperature
t_C=t*0.01 - 40; //calc. temperature from ticks
rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]
rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]
if(rh_true>100)rh_true=100; //cut if the value is outside of
if(rh_true<0.1)rh_true=0.1; //the physical possible range
*p_temperature=t_C; //return temperature
*p_humidity=rh_true; //return humidity[%RH]
}
//************************************************
// makes a measurement (humidity/temperature) with checksum
//测量一次温度/湿度,无校验
//参数:0表示温度,1表示湿度
//**************************************************
int s_measure(unsigned char mode)
{
unsigned char a,b;
s_transstart(); //启动传输
switch(mode) //发送开始测量命令
{
case 0 : s_write_byte(MEASURE_TEMP); break;
case 1 : s_write_byte(MEASURE_HUMI); break;
default : break;
}