一. 系统概述
系统利用STM32单片机作为主控单元,通过温湿度传感器和PM2.5传感器对环境进行监测。系统会实时显示温湿度及粉尘浓度,并在粉尘浓度超出预设阈值时触发报警。
二. 仿真概述
- DHT11传感器负责温湿度的检测,检测结果会在LCD1602显示屏上显示。PM2.5传感器的滑动变阻器可以用来调节,当粉尘浓度超出设定值时,系统会发出警报提示。
- 用户可以通过按键进行系统的复位操作,复位后系统的阈值将恢复到初始状态。通过加减按键可以对阈值进行调节。
三.程序设计
#include <stm32f10x.h>
#include <Lcd1602.h>
#include <key.h>
#include "dht11.h"
#include <Led.h>
#include "PCF8591.h"
int main(void)
{
u8 s,t,h,m=1,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(0xc2,1,(u8*)"c");
Lcd1602_Write_String(0x84,2,(u8*)"H:");
Lcd1602_Write_String(0xc6,1,(u8*)"%");
Lcd1602_Write_String(0x88,5,(u8*)"PM2.5");
Lcd1602_Write_String(0xca,4,(u8*)"mg");
Lcd1602_Write_String(0x8e,5,(u8*)"H");
while(1)
{
s=PCF8591_ADC_Input(0x90,1);
Lcd1602_Write_Num8(0xc8,s);
Lcd1602_Write_Num8(0xce,smax);
DHT11_Read_Data(&t,&h);
Lcd1602_Write_Num8(0xc0,t);
Lcd1602_Write_Num8(0xc4,h);
if(Key0==0) smax++;
else if(Key1==0) smax--;
if(Key2==0)
{
m=~m;
}
if(s>smax&&m==1)
{
Led1_High;
}
else Led1_Low;
}
}
24-32f-33