|
用STc12c5A60S2 采集SHt15的温湿度,在1602上显示,总是不正确,代码是参- void calc_dht90(float *p_humidity ,float *p_temperature)
- // calculates temperature [C] and humidity [%RH]
- // input : humi [Ticks] (12 bit)
- // temp [Ticks] (14 bit)
- // output: humi [%RH]
- // temp [C]
- {
- const float C1=-2.0468; // for 12 Bit
- const float C2=+0.0367; // for 12 Bit
- const float C3=-0.0000015955; // 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 [C]
- t_C=t*0.01 - 40; //calc. temperature from ticks to [C]
- 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 [C]
- *p_humidity=rh_true; //return humidity[%RH]
- }
- void main(void)
- {
- value humi_val,temp_val;
- unsigned char error,checksum;
- unsigned int wendu,shidu;
- LCD_Init();
- s_connectionreset();
- LCD_Write_String(0,0,"TE");
- LCD_Write_String(0,1,"RH");
- //*********初始化温度显示区*********
- LCD_Write_String(3,0,"TTT.TC");
- //*********初始化湿度显示区*********
- LCD_Write_String(3,1,"RRR.R%");
- delay_n10us(20000); //延时0.2s
- while(1)
- {
- error=0;
- error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI); //measure humidity
- error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP); //measure temperature
- if(error!=0) s_connectionreset(); //in case of an error: connection reset
- else
- {
- humi_val.f=(float)humi_val.i; //converts integer to float
- temp_val.f=(float)temp_val.i; //converts integer to float
- calc_dht90(&humi_val.f,&temp_val.f); //calculate humidity, temperature
- wendu=10000000*temp_val.f;
- LCD_Write_Char(3,0,wendu/1000+'0'); //显示温度百位
- LCD_Write_Char(4,0,(wendu%1000)/100+'0'); //显示温度十位
- LCD_Write_Char(5,0,(wendu%100)/10+'0'); //显示温度个位
- LCD_Write_Char(7,0,(wendu%10)+'0'); //显示温度小数点后第一位
- shidu=10000000*humi_val.f;
- LCD_Write_Char(3,1,shidu/1000+'0'); //显示湿度百位
- LCD_Write_Char(4,1,(shidu%1000)/100+'0'); //显示湿度十位
- LCD_Write_Char(5,1,(shidu%100)/10+'0'); //显示湿度个位
- LCD_Write_Char(7,1,(shidu%10)+'0'); //显示湿度小数点后第一位
- }
- //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------
- delay_n10us(80000); //延时约0.8s
- }
- }
复制代码 考了坛子里的v_hyx的代码,这是部分代码,显示温度22.4C 湿度85.7% ,但是放在温度高的地方也不变化,会是哪里问题? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|