標題: 采用SHT11的溫度濕度采集報警系統(tǒng)設計(LCD1602顯示) [打印本頁]

作者: 攀越高峰    時間: 2019-9-26 19:00
標題: 采用SHT11的溫度濕度采集報警系統(tǒng)設計(LCD1602顯示)
系統(tǒng)通過SHT11溫濕度傳感器感應周圍的環(huán)境的溫度和濕度,通過單片機對采集到的數(shù)據(jù)進行讀取處理,經(jīng)過LCD1602顯示模塊實時顯示溫濕度數(shù)據(jù),同時可以通過按鍵模塊對溫濕度報警上、下限值進行設定。當SHT11讀取的溫濕度值不再設定范圍內時,報警模塊LED燈指示故障信息,同時蜂鳴器報警;當溫濕度讀取數(shù)據(jù)正常后,LED燈熄滅,蜂鳴器關閉。



運行結果如下


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的溫濕度數(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. }
復制代碼



作者: 左右kk    時間: 2019-12-4 15:28
樓主有完整的仿真圖還有程序嗎  想借鑒一下
作者: 菜雞11111    時間: 2020-3-29 17:57
難受呀,難受呀,難受呀,但仔細想想也不是那么憋屈,突然又舒服起來了,心態(tài)有問題
作者: 42598    時間: 2020-5-6 23:00
有完整的程序嗎




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1