找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1785|回復(fù): 0
收起左側(cè)

單片機DHT11溫濕度檢測器程序仿真 超閾值電阻絲模擬加熱 水泵加濕 電機風(fēng)扇降溫

[復(fù)制鏈接]
ID:548476 發(fā)表于 2022-12-9 13:48 | 顯示全部樓層 |閱讀模式
AT89C52單片機作為數(shù)據(jù)處理器,DHT11采集溫濕度數(shù)據(jù),按鍵調(diào)整溫濕度報警閾值,LCD12864來進行顯示溫濕度實時數(shù)據(jù)和報警閾值,當DHT11檢測到的溫度高于報警閾值的時候,電阻絲進行模擬加熱,當檢測到的溫度低于報警閾值的時候,風(fēng)扇開始進行降溫;當檢測到的DHT11濕度低于報警閾值的時候,水泵進行模擬加濕,當檢測到的DHT11濕度高于報警閾值的時候,蜂鳴器進行鳴叫

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
溫濕度.png 51hei.gif

單片機源程序如下:
#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ù)功能                 : 檢測獨立按鍵是否按下,按下則返回對應(yīng)鍵值
* 輸    入       : mode=0:單次掃描按鍵
                                   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(" 當前溫度:%bu.%bu",tempH,tempL);
                delay_ms(5);
                printf ("\r\n");
                delay_ms(5);
            printf(" 當前濕度:%bu.%bu",humiH,humiL);
                delay_ms(5);
        printf ("\r\n");
                delay_ms(5);
        }
}

Keil5代碼與Proteus8.13仿真下載:
溫濕度檢測(12864).zip (173.46 KB, 下載次數(shù): 89)

評分

參與人數(shù) 1黑幣 +80 收起 理由
admin + 80 共享資料的黑幣獎勵!

查看全部評分

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

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