赞
踩
功能介绍:
0.本系统采用STC89C52作为单片机
1.LCD1602液晶实时显示当前湿度值
2.当湿度超过设定湿度阈值范围时,启动加热和风机控制继电器,否则关闭
3.按键可设定湿度阈值
4.采用DC002作为电源接口可直接输入5V给整个系统供电
原理图:
PCB:
主程序:
#include "main.h" unsigned char dispFlag = 0; //更新显示标志 enum _MODE_DF_ dispMode; unsigned char num = 0; int temp = 0; int humidity = 0; int hmMax = 60; unsigned char setIndex = 0; bit ctrlFlag = 0; //自动控制开关 bit ctrlFlag1 = 0; //手动控制开关 char dis0[16]; //定义显示区域临时存储数组 void main(void) { char channel = 0; Timer0_Init(); LCD_Init(); //初始化液晶 DelayMs(200); //延时有助于稳定 LCD_Clear(); //清屏 LCD_DispStr(0, 0, " Welcome "); DelayS(1); LCD_Clear(); //清屏 DispNormal(); while (1) //主循环 { if (dispFlag == 1) { dispFlag = 0; if (dispMode == NORMAL) { TR0 = 0; DHT11_0_ReadData(); temp = U8T_data_H; humidity = U8RH_data_H; TR0 = 1; DispNormal(); if (humidity > hmMax) //湿度大于预设值 { ctrlFlag = 1; //控制开关标志 } else { ctrlFlag = 0; } } } KeyProcess(); } } void DispNormal(void) { sprintf(dis0, "Hm:%2d%% Temp:%2d", humidity, temp); //打印温度值 LCD_DispStr(0, 0, dis0); LCD_DispOneChar(14, 0, 0xdf); //写入温度右上角点 LCD_DispOneChar(15, 0, 'C'); //写入温度的C if (ctrlFlag || ctrlFlag1) //控制开关打开 { RELAY_HEAT = ON; //开启加热 RELAY_FAN = ON; //开启通风 LCD_DispStr(0, 1, "Heat:ON Fan:ON "); } else { RELAY_HEAT = OFF; //关闭加热 RELAY_FAN = OFF; //关闭通风 LCD_DispStr(0, 1, "Heat:OFF Fan:OFF"); } } void DispSetHm(unsigned char setIndex) { LCD_DispStr(0, 0, " Set Hm Limit "); sprintf(dis0, " %2d%% ", hmMax); LCD_DispStr(0, 1, dis0); switch (setIndex) { case 1: LCD_SetCursor(8, 1, 1); break; default:; } } /*------------------------------------------------ 定时器初始化子程序 ------------------------------------------------*/ void Timer0_Init(void) { TMOD |= 0x01; //使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响 TH0 = (65536 - 18432) / 256; //重新赋值 20ms TL0 = (65536 - 18432) % 256; EA = 1; //总中断打开 ET0 = 1; //定时器中断打开 TR0 = 1; //定时器开关打开 } /*------------------------------------------------ 定时器中断子程序 ------------------------------------------------*/ void Timer0_Interrupt(void) interrupt 1 { static unsigned char time20ms = 0; TH0 = (65536 - 18432) / 256; //重新赋值 20ms TL0 = (65536 - 18432) % 256; time20ms++; if (time20ms > 100) { time20ms = 0; dispFlag = 1; //读标志位置1 } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。