void Sht_Measure(void)
{
u16 temp;
u8 temp1, temp2;
u8 rh1, rh2;
u32 rh = 0;
s32 rh_lin;
Sht_Start();
Sht_Send_Byte(T);
if(Sht_Read_Ack()) //读ACK
{
printf("ACK error \r\n");
return;
}
Set_Data_In();
while(SHTDATA) //延时等待DATA变低
{
Led_Run();
}
temp1 = Sht_Read_Byte(); //读高8位数据
Sht_Send_Ack(); //发送一个ACK
temp2 = Sht_Read_Byte();
temp=(temp1<<8)+temp2; //读低8位并合成一个16位数据
Sht_Send_Ack(); //发送一个ACK
Sht_Read_Byte(); //读CRC
Sht_Send_Ack(); //发送一个ACK
//printf("%x %x %d \r\n", temp1, temp2, temp);
temp_true=temp-3963; //14bit温度转换,其结果为实际温度*100
Sht_Start();
Sht_Send_Byte(RH);
if(Sht_Read_Ack()) //读ACK
{
printf("ACK error \r\n");
return;
}
Set_Data_In();
while(SHTDATA) //延时等待DATA变低
{
Led_Run();
}
rh1 = Sht_Read_Byte(); //读高8位数据
Sht_Send_Ack(); //发送一个ACK
rh2 = Sht_Read_Byte();
rh=(rh1<<8)+rh2; //读低8位并合成一个16位数据
Sht_Send_Ack(); //发送一个ACK
Sht_Read_Byte(); //读CRC
Sht_Send_Ack(); //发送一个ACK
rh_lin = 0.0405*rh - 400 - 0.0000028*rh*rh;
rh_true = (temp_true+3963-2500)*(1+0.00008*rh)+rh_lin;
}
#endif
|