系統通過SHT11溫濕度傳感器感應周圍的環境的溫度和濕度,通過單片機對采集到的數據進行讀取處理,經過LCD1602顯示模塊實時顯示溫濕度數據,同時可以通過按鍵模塊對溫濕度報警上、下限值進行設定。當SHT11讀取的溫濕度值不再設定范圍內時,報警模塊LED燈指示故障信息,同時蜂鳴器報警;當溫濕度讀取數據正常后,LED燈熄滅,蜂鳴器關閉。
系統框架.jpg (38.93 KB, 下載次數: 89)
下載附件
2019-9-26 18:51 上傳
運行結果如下
1.png (26.5 KB, 下載次數: 99)
下載附件
2019-9-26 18:53 上傳
SHT11程序:
- /*********************************************************/
- // SHT11溫濕度檢測
- /*********************************************************/
- char ShtMeasure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
- {
- unsigned error=0;
- unsigned int i;
- ShtTransStart();
- switch(mode)
- {
- case 1 :
- error+=ShtWriteByte(0x03);
- break;
- case 2 :
- error+=ShtWriteByte(0x05);
- break;
- default:
- break;
- }
- for(i=0;i<65535;i++)
- if(Data_P==0)
- break;
- if(Data_P)
- error+=1;
- *(p_value) =ShtReadByte(1);
- *(p_value+1)=ShtReadByte(1);
- *p_checksum =ShtReadByte(0);
- return error;
- }
- /*********************************************************/
- // SHT11溫濕度值標度變換及溫度補償
- /*********************************************************/
- void CalcSHT11(float *p_humidity ,float *p_temperature)
- {
- const float C1=-4.0;
- const float C2=+0.0405;
- const float C3=-0.0000028;
- const float T1=+0.01;
- const float T2=+0.00008;
- float rh=*p_humidity;
- float t=*p_temperature;
- float rh_lin;
- float rh_true;
- float t_C;
- t_C=t*0.01 - 40;
- rh_lin=C3*rh*rh + C2*rh + C1;
- rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;
- *p_humidity=rh_true;
- }
- /*********************************************************/
- // 溫度校正
- /*********************************************************/
- unsigned char TempCorrect(int temp)
- {
- if(temp<0) temp=0;
- if(temp>970) temp=970;
- if(temp>235) temp=temp+10;
- if(temp>555) temp=temp+10;
- if(temp>875) temp=temp+10;
- temp=(temp%1000)/10;
- return temp;
- }
- /*********************************************************/
- // 濕度校正
- /*********************************************************/
- unsigned char HumiCorrect(unsigned int humi)
- {
- if(humi>999) humi=999;
- if((humi>490)&&(humi<951)) humi=humi-10;
- humi=(humi%1000)/10;
- return humi;
- }
- /*********************************************************/
- // 讀取SHT11的溫濕度數據
- /*********************************************************/
- void ReadShtData()
- {
- value humi_val,temp_val;
- unsigned char error;
- unsigned char checksum;
- unsigned int temp1,humi1;
- error=0;
- error+=ShtMeasure((unsigned char*)&temp_val.i,&checksum,1);
- error+=ShtMeasure((unsigned char*)&humi_val.i,&checksum,2);
- if(error!=0)
- ShtConnectReset();
- else
- {
- humi_val.f=(float)humi_val.i;
- temp_val.f=(float)temp_val.i;
- CalcSHT11(&humi_val.f,&temp_val.f);
- temp1=temp_val.f*10;
- temp=TempCorrect(temp1);
- humi=HumiCorrect(humi1);
- humi = humi + 2;
- }
- }
復制代碼
|