|
AT89C52單片機(jī)作為數(shù)據(jù)處理器,DHT11采集溫濕度數(shù)據(jù),按鍵調(diào)整溫濕度報(bào)警閾值,LCD12864來(lái)進(jìn)行顯示溫濕度實(shí)時(shí)數(shù)據(jù)和報(bào)警閾值,當(dāng)DHT11檢測(cè)到的溫度高于報(bào)警閾值的時(shí)候,電阻絲進(jìn)行模擬加熱,當(dāng)檢測(cè)到的溫度低于報(bào)警閾值的時(shí)候,風(fēng)扇開(kāi)始進(jìn)行降溫;當(dāng)檢測(cè)到的DHT11濕度低于報(bào)警閾值的時(shí)候,水泵進(jìn)行模擬加濕,當(dāng)檢測(cè)到的DHT11濕度高于報(bào)警閾值的時(shí)候,蜂鳴器進(jìn)行鳴叫
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
溫濕度.png (48.87 KB, 下載次數(shù): 23)
下載附件
2022-12-9 13:47 上傳
51hei.gif (93.94 KB, 下載次數(shù): 25)
下載附件
2022-12-9 15:58 上傳
單片機(jī)源程序如下:
#include "config.h"
#include "lcd12864.h"
#include "dht11.h"
#include "stdio.h"
#include "intrins.h"
#include "math.h"
#include "uart.h"
#include "key.h"
uint t = 20;
uint z = 40;
unsigned char tempH,tempL,humiH,humiL;
/*******************************************************************************
* 函 數(shù) 名 : Display
* 函數(shù)功能 : 顯示溫濕度閾值
*******************************************************************************/
void Display(void)
{
uchar t_Buffer[3];
uchar z_Buffer[3];
delay_ms(100);
t_Buffer[0] = t/10+0x30;
t_Buffer[1] = t%10+0x30;
t_Buffer[2] = '\0';
Write_String(2,72,0,t_Buffer);
delay_ms(100);
z_Buffer[0] = z/10+0x30;
z_Buffer[1] = z%10+0x30;
z_Buffer[2] = '\0';
Write_String(6,72,0,z_Buffer);
}
/*******************************************************************************
* 函 數(shù) 名 : key_press
* 函數(shù)功能 : 檢測(cè)獨(dú)立按鍵是否按下,按下則返回對(duì)應(yīng)鍵值
* 輸 入 : mode=0:?jiǎn)未螔呙璋存I
mode=1:連續(xù)掃描按鍵
* 輸 出 :
KEY1_PRESS:K1按下溫度閾值加1
KEY2_PRESS:K2按下溫度閾值減1
KEY3_PRESS:K3按下濕度閾值加1
KEY4_PRESS:K4按下濕度閾值減1
KEY_UNPRESS:未有按鍵按下
*******************************************************************************/
void key_press()
{
uchar key = 0;
key = key_scan(1);
if (key==KEY1_PRESS)
{
if(t<100)
t++;
}
else if (key==KEY2_PRESS)
{
if (t>0)
t--;
}
if (key==KEY3_PRESS)
{
if(z<100)
z++;
}
else if (key==KEY4_PRESS)
{
if (z>0)
z--;
}
}
void baojing(void)
{
{
if (tempH > t)
{
Fengsan = 0;
Relay = 1;
}
else
{
Fengsan = 1;
Relay = 0;
}
}
{
if (humiH > z)
{
Suibeng = 1;
Beep = 1;
}
else
{
Suibeng = 0;
Beep = 0;
}
}
}
/*******************************************************************************
* 函 數(shù) 名 : 主函數(shù)
*******************************************************************************/
void main()
{
uchar temp_buf[3],humi_buf[3];
UartInit();
dht11_rst();
if(dht11_check()<0)
{
printf("DHT11 ERROR!\r\n");
}
else
{
printf("DHT11 OK\r\n");
}
// EA = 1;
Init_12864();
Qin();
Write_String(0,0,0,"溫度");
Write_String(0,32,0,":");
Write_String(0,60,0,"℃");
Write_String(2,0,0,"溫度閾值");
Write_String(2,64,0,":");
Write_String(2,90,0,"℃");
Write_String(4,0,0,"濕度");
Write_String(4,32,0,":");
Write_String(4,60,0,"%RH");
Write_String(6,0,0,"濕度閾值");
Write_String(6,64,0,":");
Write_String(6,90,0,"%RH");
while(1)
{
Display();
key_press();
dht11_Read_Data(&tempH,&tempL,&humiH,&humiL);
delay_ms(500);
// Write_String(2,40,0,"&tempH");
temp_buf[0]=tempH/10+0x30;
temp_buf[1]=tempH%10+0x30;
humi_buf[0]=humiH/10+0x30;
humi_buf[1]=humiH%10+0x30;
Write_String(0,40,0,temp_buf);
Write_String(4,40,0,humi_buf);
baojing();
// printf("TEMP:%bu.%bu HUMI:%bu.%bu",tempH,tempL,humiH,humiL);
// printf ("\r\n");
printf(" 當(dāng)前溫度:%bu.%bu",tempH,tempL);
delay_ms(5);
printf ("\r\n");
delay_ms(5);
printf(" 當(dāng)前濕度:%bu.%bu",humiH,humiL);
delay_ms(5);
printf ("\r\n");
delay_ms(5);
}
}
Keil5代碼與Proteus8.13仿真下載:
溫濕度檢測(cè)(12864).zip
(173.46 KB, 下載次數(shù): 89)
2022-12-9 13:48 上傳
點(diǎn)擊文件名下載附件
程序壓縮包 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|