赞
踩
本次设计采用基于单片机的智能加湿器系统,以STM32F103C8T6和温湿度传感器DHT11为核心,通过湿度传感器采集和转换温湿度信号,再利用单片机进行数据分析和处理,实现智能开启和关闭加湿功能,并通过继电器控制加湿器,以实现对湿度的精准调节。实现加湿器防干烧和实时显示室内相对湿度的功能,需要外接辅助电路的支持。由于其简洁明了的电路设计、易于读取的特点以及高精度的检测能力,该系统在可靠性和实用价值方面均呈现出卓越的水平。
- Main主程序
- #include "common.h"
- #include "lcd1602.h"
- #include "dht.h"
-
- extern unsigned char U8RH_data_H;
- extern unsigned char U8T_data_H;
-
- sbit key1 = P1^0;//切换键
- sbit key2 = P1^1;//加键
- sbit key3 = P1^2;//减键
-
- sbit RELAY = P3^7;//继电器
-
- sbit beep = P2^0;//蜂鸣器
- sbit ShuiWei=P1^4;//水位传感器
-
- unsigned char HumiMin = 15;//湿度下限
- unsigned char setn = 0;//设置标志
-
- bit mode = 0;//模式:0是自动模式,1是手动模式
-
- void keyscan()
- {
- if(key1 == 0)//切换键按下
- {
- delay_ms(10);
- if(key1 == 0)
- {
- beep = 0;
- delay_ms(100);
- beep = 1;
- while(key1 == 0);//等待按键松开
- mode = !mode;
- if(mode==0)lcd_write_str(14,0,"Zd");
- else lcd_write_str(14,0,"Sd");
- }
- }
- if(key2 == 0)
- {
- delay_ms(10);
- if(key2 == 0)
- {
- beep = 0;
- delay_ms(100);
- beep = 1;
- while(key2 == 0);
- if(mode==0)//在自动模式下是加键
- {
- if(HumiMin < 99)HumiMin++;
- lcd_write_char(9,1,HumiMin/10+0x30);
- lcd_write_char(10,1,HumiMin%10+0x30);
- }
- else//在手动模式下是手动开启键
- {
- RELAY = 0;//继电器开启
- }
- }
- }
- if(key3 == 0)
- {
- delay_ms(10);
- if(key3 == 0 )
- {
- beep = 0;
- delay_ms(100);
- beep = 1;
- while(key3 == 0);
- if(mode==0)//在自动模式下是减键
- {
- if(HumiMin > 0)HumiMin--;
- lcd_write_char(9,1,HumiMin/10+0x30);
- lcd_write_char(10,1,HumiMin%10+0x30);
- }
- else//在手动模式下是手动关闭键
- {
- RELAY = 1;//继电器关闭
- }
- }
- }
- }
-
- void main()
- {
- unsigned int count;
- short temperature;
- short humidity;
- bit shanshuo=0;
-
- lcd_init();//1602液晶初始化
- lcd_write_str(0,0,"00C Humi:00% Zd");
- lcd_write_str(0,1," Minimum:00% ");
- lcd_write_char(9,1,HumiMin/10+0x30);
- lcd_write_char(10,1,HumiMin%10+0x30);
- do
- {
- RH();delay_ms(100);
- }while(U8RH_data_H==0&&U8T_data_H==0);
- while(1)
- {
- keyscan();//按键扫描
- if(count++>=500)//延时一段时间
- {
- count=0;
- shanshuo=!shanshuo;
-
- RH();
-
- //读出温湿度,只取整数部分
- humidity = U8RH_data_H;
- temperature = U8T_data_H;
-
- lcd_write_char(0,0,temperature/10+0x30);
- lcd_write_char(1,0,temperature%10+0x30);
- lcd_write_char(9,0,humidity/10+0x30);
- lcd_write_char(10,0,humidity%10+0x30);
-
- if(ShuiWei==0 && shanshuo)//缺水
- {
- lcd_write_str(14,1,"Qs");
- beep = 0;
- }
- else
- {
- lcd_write_str(14,1," ");
- beep = 1;
- }
- if(mode==0)//在自动模式下
- {
- if(humidity<=HumiMin)RELAY=0; else RELAY=1;//湿度低于下限,开启加湿
- }
- }
- delay_ms(1);
- }
- }
需要私聊,微信:lwfw123456789
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。