一. 系统概述
环境监测系统采用STM32单片机作为主控核心,结合温湿度传感器实现环境的温湿度检测,并通过烟雾传感器监测烟雾浓度。监测到的数据将实时显示在显示屏上。当检测到温湿度超出设定的范围时,系统会自动进行调整;若烟雾浓度超过设定的阈值,则系统会触发报警。
二. 仿真概述
- 当湿度超出预设上限时,系统会自动启动除湿功能。
- 若湿度低于设定的下限,系统会启动加湿装置以提升湿度。
- 当温度超出设定的上限时,系统将启动风扇以降低温度。
- 如果温度低于设定的下限,系统将启用加热装置以提升温度。
- 当烟雾浓度超过设定阈值时,系统会触发警报以提醒用户。
- 用户可以通过按下设置按钮来调整温度和烟雾浓度的阈值。设置完成后,需要按下确认按钮以保存设置。
三.程序设计
#include <stm32f10x.h>
#include <Lcd1602.h>
#include <key.h>
#include "dht11.h"
#include <Led.h>
#include "PCF8591.h"
int main(void)
{
u8 t,h,s,m=0,tmax=28,tmin=26,hmax=80,hmin=78,smax=30;
Lcd1602_Init();//pa0-7 pb8-10
DHT11_Init();//pa12
Led_Init();//pc0-4
Key_Init();//pb12-15
PCF8591_Init();
Lcd1602_Write_String(0x80,2,(u8*)"T:");
Lcd1602_Write_String(0x80+4,1,(u8*)"c");
Lcd1602_Write_String(0x86+2,1,(u8*)"-");
Lcd1602_Write_String(0xc0,2,(u8*)"H:");
Lcd1602_Write_String(0xc0+4,1,(u8*)"%");
Lcd1602_Write_String(0xc6+2,1,(u8*)"-");
Lcd1602_Write_String(0x8c,2,(u8*)"S:");
Led1_Low;Led3_Low;Led4_Low;Led5_Low;
while(1)
{
s=PCF8591_ADC_Input(0x90,1);
Lcd1602_Write_Num8(0x8e,s);
DHT11_Read_Data(&t,&h);
Lcd1602_Write_Num8(0x82,t);
Lcd1602_Write_Num8(0xc2,h);
Lcd1602_Write_Num8(0x86,tmin);
Lcd1602_Write_Num8(0xc6,hmin);
Lcd1602_Write_Num8(0x89,tmax);
Lcd1602_Write_Num8(0xc9,hmax);
Lcd1602_Write_Num8(0xce,smax);
delay_ms(500);
if(Key2==0)
{
m++;
if(m==6) m=0;
}
if(Key3==0) m=0;
if(m==1)
{
Lcd1602_Write_String(0x86,2,(u8*)" ");
if(Key0==0) tmin++;
else if(Key1==0) tmin--;
}
else if(m==2)
{
Lcd1602_Write_String(0x89,2,(u8*)" ");
if(Key0==0) tmax++;
else if(Key1==0) tmax--;
}
else if(m==3)
{
Lcd1602_Write_String(0xc6,2,(u8*)" ");
if(Key0==0) hmin++;
else if(Key1==0) hmin--;
}
else if(m==4)
{
Lcd1602_Write_String(0xc9,2,(u8*)" ");
if(Key0==0) hmax++;
else if(Key1==0) hmax--;
}
else if(m==5)
{
Lcd1602_Write_String(0xce,2,(u8*)" ");
if(Key0==0) smax++;
else if(Key1==0) smax--;
}
}
}
24-32f-31