基于单片机的温湿度检测系统主程序流程图,温、湿度检测程序流程图,报警程序流程图,传感器是dht11

#include<reg52.h>
#include"lcd1602.h"
#include"dht11.h"
#define uint unsigned int //无符号整型 宏定义 变量范围0~65535
#define uchar unsigned char //无符号字符型 宏定义 变量范围0~255
sbit Key1=P3^5;
sbit Key2=P3^6;
sbit Key3=P3^7;
sbit FM=P2^0;
sbit LED1=P2^2;
sbit LED2=P2^1;
uchar Alarm_Wen=35;//温度报警值
uchar Alarm_Shi=60;//湿度报警值
extern unsigned char table_dht11[5];
uchar flag_Key,flag_Show;
//延时ms
void Delay_ms(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void LCD_Show(void)
{
//显示湿度
write_zifu(0,0,'S');
write_zifu(0,1,'h');
write_zifu(0,2,'i');
write_zifu(0,3,':');
write_zifu(0,4,table_dht11[0]/10+0x30);
write_zifu(0,5,table_dht11[0]%10+0x30);

//显示温度
write_zifu(1,0,'W');
write_zifu(1,1,'e');
write_zifu(1,2,'n');
write_zifu(1,3,':');
write_zifu(1,4,table_dht11[2]/10+0x30);
write_zifu(1,5,table_dht11[2]%10+0x30);

//湿度报警值
write_zifu(0,12,'S');
if(flag_Show==1)
{
lcd1602_guanbiao(1,12);
Delay_ms(100);
lcd1602_guanbiao(0,12);
}

write_zifu(0,13,':');
write_zifu(0,14,Alarm_Shi/10+0x30);
write_zifu(0,15,Alarm_Shi%10+0x30);
//温度报警值
write_zifu(1,12,'W');
if(flag_Show==2)
{
lcd1602_guanbiao(1,12+0x40);
Delay_ms(100);
lcd1602_guanbiao(0,12+0x40);
}
write_zifu(1,13,':');
write_zifu(1,14,Alarm_Wen/10+0x30);
write_zifu(1,15,Alarm_Wen%10+0x30);
}
void Key_Detection(void)
{
if((Key1&Key2&Key3)==0)
{
Delay_ms(5);
if(Key1==0)
flag_Show++;
if(Key2==0)
flag_Key=1;
if(Key3==0)
flag_Key=2;
while(Key1==0 | Key2==0 | Key3==0);
}
}
void Alarm_Detection(void)
{
uchar i,j;
i=table_dht11[0]; //湿度值
j=table_dht11[2]; //温度值
if(j>=Alarm_Wen)
{
FM=0;
LED1=0;
LED2=1;
}
else
{
if(i>=Alarm_Shi)
{
FM=0;
LED1=1;
LED2=0;
}
else
{
FM=1;
LED1=1;
LED2=1;
}
}
}
void main(void)
{
init_1602();
clear_1602();
init_1602_dis_csf();
Delay_ms(1000);
clear_1602();
while(1)
{

LCD_Show();
Key_Detection();//按键检查

if(flag_Show!=0)
{

if(flag_Key==1)
{
flag_Key=0;
if(flag_Show==1)
Alarm_Shi++;
if(flag_Show==2)
Alarm_Wen++;
if(Alarm_Wen>100)
Alarm_Wen=0;
if(Alarm_Shi>100)
Alarm_Shi=0;
}
if(flag_Key==2)
{
flag_Key=0;
if(flag_Show==1)
Alarm_Shi--;
if(flag_Show==2)
Alarm_Wen--;
if(Alarm_Wen>100)
Alarm_Wen=99;
if(Alarm_Shi>100)
Alarm_Shi=99;
}
if(flag_Show==3)
{
flag_Show=0;
}
}
else
{
dst11();
Alarm_Detection();//报警检查
}
}
}

第1个回答  2021-05-20
图4.1 系统主程序流程图

图4.2按键子程序流程图
相似回答