系統(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)閉。
系統(tǒng)框架.jpg (38.93 KB, 下載次數(shù): 89)
下載附件
2019-9-26 18:51 上傳
運(yùn)行結(jié)果如下
1.png (26.5 KB, 下載次數(shù): 99)
下載附件
2019-9-26 18:53 上傳
SHT11程序:
- /*********************************************************/
- // SHT11溫濕度檢測(cè)
- /*********************************************************/
- 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溫濕度值標(biāo)度變換及溫度補(bǔ)償
- /*********************************************************/
- 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的溫濕度數(shù)據(jù)
- /*********************************************************/
- 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;
- }
- }
復(fù)制代碼
|