搜索
bottom↓
回复: 0

51采集SHT15温湿度 1602显示不对,帮忙看看?

[复制链接]

出0入0汤圆

发表于 2012-7-28 21:10:40 | 显示全部楼层 |阅读模式
用STc12c5A60S2 采集SHt15的温湿度,在1602上显示,总是不正确,代码是参
  1. void calc_dht90(float *p_humidity ,float *p_temperature)
  2. // calculates temperature [C] and humidity [%RH]
  3. // input :  humi [Ticks] (12 bit)
  4. //          temp [Ticks] (14 bit)
  5. // output:  humi [%RH]
  6. //          temp [C]
  7. {
  8.   const float C1=-2.0468;              // for 12 Bit
  9.   const float C2=+0.0367;           // for 12 Bit
  10.   const float C3=-0.0000015955;        // for 12 Bit
  11.   const float T1=+0.01;             // for 14 Bit @ 5V
  12.   const float T2=+0.00008;           // for 14 Bit @ 5V

  13.    float rh=*p_humidity;             // rh:      Humidity [Ticks] 12 Bit
  14.   float t=*p_temperature;           // t:       Temperature [Ticks] 14 Bit
  15.   float rh_lin;                     // rh_lin:  Humidity linear
  16.   float rh_true;                    // rh_true: Temperature compensated humidity
  17.   float t_C;                        // t_C   :  Temperature [C]

  18.   t_C=t*0.01 - 40;                  //calc. temperature from ticks to [C]
  19.   rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH]
  20.   rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;   //calc. temperature compensated humidity [%RH]
  21.   if(rh_true>100)rh_true=100;       //cut if the value is outside of
  22.   if(rh_true<0.1)rh_true=0.1;       //the physical possible range  

  23.   *p_temperature=t_C;               //return temperature [C]
  24.   *p_humidity=rh_true;              //return humidity[%RH]
  25. }
  26. void main(void)
  27. {
  28.                 value humi_val,temp_val;
  29.         unsigned char error,checksum;
  30.         unsigned int wendu,shidu;
  31.         LCD_Init();       
  32.         s_connectionreset();
  33.         LCD_Write_String(0,0,"TE");
  34.              LCD_Write_String(0,1,"RH");


  35. //*********初始化温度显示区*********
  36.         LCD_Write_String(3,0,"TTT.TC");

  37. //*********初始化湿度显示区*********
  38.         LCD_Write_String(3,1,"RRR.R%");

  39.         delay_n10us(20000);     //延时0.2s

  40.         while(1)
  41.         {
  42.                   error=0;
  43.           error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity
  44.           error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
  45.           if(error!=0) s_connectionreset();                 //in case of an error: connection reset
  46.           else
  47.           {
  48.                     humi_val.f=(float)humi_val.i;                   //converts integer to float
  49.             temp_val.f=(float)temp_val.i;                   //converts integer to float
  50.             calc_dht90(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
  51.                                     wendu=10000000*temp_val.f;
  52.                         LCD_Write_Char(3,0,wendu/1000+'0');              //显示温度百位
  53.             LCD_Write_Char(4,0,(wendu%1000)/100+'0');        //显示温度十位
  54.             LCD_Write_Char(5,0,(wendu%100)/10+'0');          //显示温度个位
  55.                      LCD_Write_Char(7,0,(wendu%10)+'0');              //显示温度小数点后第一位

  56.                                         shidu=10000000*humi_val.f;
  57.                         LCD_Write_Char(3,1,shidu/1000+'0');               //显示湿度百位
  58.             LCD_Write_Char(4,1,(shidu%1000)/100+'0');         //显示湿度十位
  59.             LCD_Write_Char(5,1,(shidu%100)/10+'0');           //显示湿度个位
  60.                         LCD_Write_Char(7,1,(shidu%10)+'0');               //显示湿度小数点后第一位
  61.           }
  62.           //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------      
  63.                   delay_n10us(80000);                                //延时约0.8s
  64.         }
  65. }
复制代码
考了坛子里的v_hyx的代码,这是部分代码,显示温度22.4C  湿度85.7%  ,但是放在温度高的地方也不变化,会是哪里问题?

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-26 16:17

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表