找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 4375|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

采用SHT11的溫度濕度采集報(bào)警系統(tǒng)設(shè)計(jì)(LCD1602顯示)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
系統(tǒng)通過(guò)SHT11溫濕度傳感器感應(yīng)周?chē)沫h(huán)境的溫度和濕度,通過(guò)單片機(jī)對(duì)采集到的數(shù)據(jù)進(jìn)行讀取處理,經(jīng)過(guò)LCD1602顯示模塊實(shí)時(shí)顯示溫濕度數(shù)據(jù),同時(shí)可以通過(guò)按鍵模塊對(duì)溫濕度報(bào)警上、下限值進(jìn)行設(shè)定。當(dāng)SHT11讀取的溫濕度值不再設(shè)定范圍內(nèi)時(shí),報(bào)警模塊LED燈指示故障信息,同時(shí)蜂鳴器報(bào)警;當(dāng)溫濕度讀取數(shù)據(jù)正常后,LED燈熄滅,蜂鳴器關(guān)閉。



運(yùn)行結(jié)果如下


SHT11程序:

  1. /*********************************************************/
  2. // SHT11溫濕度檢測(cè)
  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溫濕度值標(biāo)度變換及溫度補(bǔ)償
  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的溫濕度數(shù)據(jù)
  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. }
復(fù)制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:645846 發(fā)表于 2019-12-4 15:28 | 只看該作者
樓主有完整的仿真圖還有程序嗎  想借鑒一下
回復(fù)

使用道具 舉報(bào)

板凳
ID:180018 發(fā)表于 2020-3-29 17:57 | 只看該作者
難受呀,難受呀,難受呀,但仔細(xì)想想也不是那么憋屈,突然又舒服起來(lái)了,心態(tài)有問(wèn)題
回復(fù)

使用道具 舉報(bào)

地板
ID:742556 發(fā)表于 2020-5-6 23:00 | 只看該作者
有完整的程序嗎
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表