找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3649|回复: 3
收起左侧

采用SHT11的温度湿度采集报警系统设计(LCD1602显示)

[复制链接]
ID:614205 发表于 2019-9-26 19:00 | 显示全部楼层 |阅读模式
系统通过SHT11温湿度传感器感应周围的环境的温度和湿度,通过单片机对采集到的数据进行读取处理,经过LCD1602显示模块实时显示温湿度数据,同时可以通过按键模块对温湿度报警上、下限值进行设定。当SHT11读取的温湿度值不再设定范围内时,报警模块LED灯指示故障信息,同时蜂鸣器报警;当温湿度读取数据正常后,LED灯熄灭,蜂鸣器关闭。

系统框架.jpg

运行结果如下
1.png

SHT11程序:

  1. /*********************************************************/
  2. // SHT11温湿度检测
  3. /*********************************************************/
  4. char ShtMeasure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
  5. {
  6.         unsigned error=0;
  7.         unsigned int i;
  8.         ShtTransStart();  
  9.         switch(mode)   
  10.         {
  11.                 case 1 :  
  12.                         error+=ShtWriteByte(0x03);
  13.                         break;
  14.                 case 2 :                  
  15.                         error+=ShtWriteByte(0x05);
  16.                         break;
  17.                 default:
  18.                         break;
  19.         }
  20.         for(i=0;i<65535;i++)
  21.                 if(Data_P==0)
  22.                         break;  
  23.                 if(Data_P)
  24.                         error+=1;  
  25.         *(p_value) =ShtReadByte(1);
  26.         *(p_value+1)=ShtReadByte(1);
  27.         *p_checksum =ShtReadByte(0);
  28.         return error;         
  29. }
  30. /*********************************************************/
  31. // SHT11温湿度值标度变换及温度补偿
  32. /*********************************************************/
  33. void CalcSHT11(float *p_humidity ,float *p_temperature)
  34. {
  35.         const float C1=-4.0;         
  36.         const float C2=+0.0405;        
  37.         const float C3=-0.0000028;
  38.         const float T1=+0.01;         
  39.         const float T2=+0.00008;         
  40.         float rh=*p_humidity;
  41.         float t=*p_temperature;        
  42.         float rh_lin;        
  43.         float rh_true;        
  44.         float t_C;
  45.         t_C=t*0.01 - 40;        
  46.         rh_lin=C3*rh*rh + C2*rh + C1;
  47.         rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;
  48.         *p_humidity=rh_true;
  49. }
  50. /*********************************************************/
  51. // 温度校正
  52. /*********************************************************/
  53. unsigned char TempCorrect(int temp)
  54. {
  55.         if(temp<0)        temp=0;
  56.         if(temp>970)  temp=970;
  57.         if(temp>235)  temp=temp+10;
  58.         if(temp>555)  temp=temp+10;
  59.         if(temp>875)  temp=temp+10;
  60.         temp=(temp%1000)/10;
  61.         return temp;
  62. }
  63. /*********************************************************/
  64. // 湿度校正
  65. /*********************************************************/
  66. unsigned char HumiCorrect(unsigned int humi)
  67. {
  68.         if(humi>999)  humi=999;
  69.         if((humi>490)&&(humi<951))  humi=humi-10;
  70.         humi=(humi%1000)/10;
  71.         return humi;
  72. }
  73. /*********************************************************/
  74. // 读取SHT11的温湿度数据
  75. /*********************************************************/
  76. void ReadShtData()
  77. {
  78.         value humi_val,temp_val;
  79.         unsigned char error;
  80.         unsigned char checksum;  
  81.         unsigned int temp1,humi1;        
  82.         error=0;
  83.         error+=ShtMeasure((unsigned char*)&temp_val.i,&checksum,1);
  84.         error+=ShtMeasure((unsigned char*)&humi_val.i,&checksum,2);

  85.         if(error!=0)
  86.                 ShtConnectReset();
  87.         else
  88.         {
  89.                 humi_val.f=(float)humi_val.i;
  90.                 temp_val.f=(float)temp_val.i;
  91.                 CalcSHT11(&humi_val.f,&temp_val.f);         
  92.                 temp1=temp_val.f*10;
  93.                 temp=TempCorrect(temp1);
  94.                 humi=HumiCorrect(humi1);
  95.        humi = humi + 2;
  96.         }

  97. }
复制代码


回复

使用道具 举报

ID:645846 发表于 2019-12-4 15:28 | 显示全部楼层
楼主有完整的仿真图还有程序吗  想借鉴一下
回复

使用道具 举报

ID:180018 发表于 2020-3-29 17:57 | 显示全部楼层
难受呀,难受呀,难受呀,但仔细想想也不是那么憋屈,突然又舒服起来了,心态有问题
回复

使用道具 举报

ID:742556 发表于 2020-5-6 23:00 | 显示全部楼层
有完整的程序吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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