功能介绍:
0.本系统采用STC89C52作为单片机
1.系统实时监测当前的雨滴、温湿度、风速,烟雾浓度
2.支持手动/自动两种模式
3.自动模式下
窗户关闭状态下,当烟雾浓度超过阈值,打开窗户,或者环境均在阈值范围以内,打开窗户。其中烟雾浓度过高的情况,蜂鸣器将报警,并需要手动解除报警
窗户开启状态下,当窗户外有人或温湿度超过阈值或风速过高,窗户关闭。其中窗户外有人的情况,蜂鸣器将报警,并需要手动解除报警
4.按键可设定阈值,手动控制窗户,切换工作模式
5.采用DC002作为电源接口可直接输入5V给整个系统供电
原理图:
PCB:
主程序:
#include "main.h"
enum _MODE_DF_ dispMode;
bit modeFlag = AUTO;
uchar motorFlag = 0;
bit motorDir = 1;
bit alarmFlag = 0;
char motorCnt=0;
uchar setIndex = 0;
uint humidity;
uint temperature;
uint gas;
uint rain;
uint windSpeed;
uint hmMin= 25;
uint hmMax= 50;
uint tempMin = 25;
uint tempMax = 40;
uint gasMin = 30;
uint gasMax = 60;
uint rainMin = 30;
uint rainMax = 60;
uint windSpeedMin = 5;
uint windSpeedMax = 20;
bit dispFlag = 0;
char dis[16];
void main()
{
modeFlag = MANUAL;
Timer0_Init();
LCD_Init();
DelayMs(200);
LCD_DispStr(4, 0, "Welcome!");
LCD_Clear();
BYJ48 = ((BYJ48 & 0xF0) | REV[0]);
ULN_DQ3 = BIT3; ULN_DQ2 = BIT2; ULN_DQ1 = BIT1; ULN_DQ0 = BIT0;
while (1)
{
if (dispFlag == 1)
{
dispFlag = 0;
if (dispMode == NORMAL)
{
DispNormal();
}
}
if (modeFlag == AUTO)
{
if (motorFlag == 0 || motorFlag == 1)
{
if (gas > gasMax)
{
motorFlag = 1;
motorDir = 0;
alarmFlag = 1;
modeFlag = MANUAL;
}
else
{
if (IR_PIN == 0)
{
}
else
{
if (rain > rainMax)
{
}
else
{
if (humidity > hmMax || temperature > tempMax)
{
}
else
{
if (windSpeed > windSpeedMax)
{
}
else
{
motorFlag = 1;
motorDir = 0;
}
}
}
}
}
}
else if (motorFlag == 2 || motorFlag == 1)
{
if (IR_PIN == 0)
{
motorFlag = 1;
motorDir = 1;
alarmFlag = 1;
modeFlag = MANUAL;
}
else
{
if (rain > rainMax)
{
motorFlag = 1;
motorDir = 1;
}
else
{
if (humidity > hmMax || temperature > tempMax)
{
motorFlag = 1;
motorDir = 1;
}
else
{
if (windSpeed > windSpeedMax)
{
motorFlag = 1;
motorDir = 1;
}
}
}
}
}
}
if (alarmFlag == 1)
{
BUZZER = ON;
}
else
{
BUZZER = OFF;
}
KeyProcess();
}
}
void Timer0_Init(void)
{
TMOD |= 0x01;
TL0 = 0x66;
TH0 = 0xFC;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void Timer0_Interrupt(void) interrupt 1
{
static unsigned int time1ms = 0;
TL0 = 0x66;
TH0 = 0xFC;
time1ms++;
if (time1ms > 500)
{
dispFlag = 1;
time1ms = 0;
}
if (motorFlag == 1)
{
if (motorDir == 1)
{
motorCnt++;
if (motorCnt >= 8)
{
motorCnt = 0;
}
BYJ48 = ((BYJ48 & 0xF0) | REV[motorCnt % 8]);
ULN_DQ3 = BIT3; ULN_DQ2 = BIT2; ULN_DQ1 = BIT1; ULN_DQ0 = BIT0;
if (LIMIT_SWITCH1 == 0)
{
motorFlag = 0;
}
}
else
{
if (motorCnt <= 0)
{
motorCnt = 8;
}
motorCnt--;
BYJ48 = ((BYJ48 & 0xF0) | REV[motorCnt % 8]);
ULN_DQ3 = BIT3; ULN_DQ2 = BIT2; ULN_DQ1 = BIT1; ULN_DQ0 = BIT0;
if (LIMIT_SWITCH2 == 0)
{
motorFlag = 2;
}
}
}
}
void DispNormal(void)
{
unsigned char gasBuf = 0;
DHT11_0_ReadData();
humidity = U8RH_data_H;
temperature = U8T_data_H;
sprintf(dis, "H:%2d%% T:%2d", humidity, temperature);
LCD_DispStr(0, 0, dis);
LCD_DispOneChar(10, 0, 0xdf);
LCD_DispOneChar(11, 0, 'C');
LCD_DispOneChar(12, 0, ' ');
if (modeFlag == AUTO)
{
LCD_DispOneChar(13, 0, 'Z');
}
else
{
LCD_DispOneChar(13, 0, 'S');
}
if (motorFlag == 0)
{
LCD_DispOneChar(14, 0, 'G');
}
else if (motorFlag == 1)
{
LCD_DispOneChar(14, 0, 'Y');
}
else
{
LCD_DispOneChar(14, 0, 'K');
}
gasBuf = ReadADC(AIN1_GND);
if (gasBuf <= 29)
{
gasBuf = 29;
}
gas = (100 * (gasBuf-29)) / 227;
rain = 100 - 100 * ReadADC(AIN0_GND) / 255;
windSpeed = 6 * 5 * ReadADC_1(AIN1_GND) / 255;
sprintf(dis, "S:%3d R:%3d W:%2d", gas, rain, windSpeed);
LCD_DispStr(0, 1, dis);
}
void DispSetHm(unsigned char setIndex)
{
LCD_DispStr(0, 0, " Set Humidity ");
sprintf(dis, " H:%2d%% L:%2d%% ", hmMax, hmMin);
LCD_DispStr(0, 1, dis);
switch (setIndex)
{
case 1: LCD_SetCursor(5, 1, 1); break;
case 2: LCD_SetCursor(11, 1, 1); break;
default:;
}
}
void DispSetTemp(unsigned char setIndex)
{
LCD_DispStr(0, 0, "Set Temperature ");
sprintf(dis, " H:%3d L:%3d ", tempMax, tempMin);
LCD_DispStr(0, 1, dis);
switch (setIndex)
{
case 1: LCD_SetCursor(6, 1, 1); break;
case 2: LCD_SetCursor(12, 1, 1); break;
default:;
}
}
void DispSetGas(unsigned char setIndex)
{
LCD_DispStr(0, 0, " Set GasLimit ");
sprintf(dis, " H:%2d%% L:%2d%% ", gasMax, gasMin);
LCD_DispStr(0, 1, dis);
switch (setIndex)
{
case 1: LCD_SetCursor(5, 1, 1); break;
case 2: LCD_SetCursor(11, 1, 1); break;
default:;
}
}
void DispSetRain(unsigned char setIndex)
{
LCD_DispStr(0, 0, " Set RainLimit ");
sprintf(dis, " H:%2d%% L:%2d%% ", rainMax, rainMin);
LCD_DispStr(0, 1, dis);
switch (setIndex)
{
case 1: LCD_SetCursor(5, 1, 1); break;
case 2: LCD_SetCursor(11, 1, 1); break;
default:;
}
}
void DispSetWindSpeed(unsigned char setIndex)
{
LCD_DispStr(0, 0, " Set SpeedLimit ");
sprintf(dis, " H:%2d L:%2d ", windSpeedMax, windSpeedMin);
LCD_DispStr(0, 1, dis);
switch (setIndex)
{
case 1: LCD_SetCursor(5, 1, 1); break;
case 2: LCD_SetCursor(11, 1, 1); break;
default:;
}
}
仿真演示视频:
https://www.bilibili.com/video/BV1yR4y1w7fb/
实物演示视频:
https://www.bilibili.com/video/BV1FU4y1271z/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)