本设计:
仿真版本:proteus 8.9 程序编译器:keil 4 设计编号:C0040
功能介绍: 以提高家居生活的安全性、舒适度、人性化为目的,设计智能家居监控系统。 (1)设计必须实现家居温度、煤气泄漏、外人闯入、火灾(烟雾)的全部检测; (2)各检测节点可通过无线方式连接到主机,检测到危险信号后,主机采用声光报警或远程报警; (3)系统具有检测灵敏、报警及时、性价比高等特点; (4)拓展部分:增加检测项目并具有可行性,除环境检测外也可增加人体信号(心率、体温)检测等。 分析:为实现温度检测、煤气和烟雾等气体检测、监控外人闯入等功能,采用NTC热敏电阻、MQ2气体检测传感器、磁控开关等传感器。
资料下载链接(可点击):
仿真图(提供源文件):
源程序(提供源文件)
#include "lcd5110.h"
#include "adc0809.h"
#include <math.h>
sbit tube = P3^2;
sbit beep = P3^6;
sbit led = P3^7;
uint temperature;
uint smoke;
uint fire;
uchar index;
uchar ad_Value[3];
float getVoltage[3];
uchar receivedata;
bit people_flag;
bit temper_flag;
bit smoke_flag;
bit fire_flag;
bit cancel_flag;
void delay(uint num)
{
uint x,y;
for(x=num;x>0;x--)
for(y=110;y>0;y--);
}
void init_interrupt(void)
{
TMOD = 0x02;
TH0 = 0xfb;
TL0 = 0xfb;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void ex_init(void)
{
IT0 = 1;
EX0 =1;
EA = 1;
}
void usart(void)
{
TMOD |= 0x20;
SCON = 0x50;
PCON = 0x00;
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1;
EA = 1;
ES = 1;
}
void display(void)
{
LCD_Set_XY(0,1);
LCD_Write_Char(temperature/1000+0x30);
LCD_Write_Char((temperature%1000)/100+0x30);
LCD_Write_Char((temperature%100)/10+0x30);
LCD_Write_Char('.');
LCD_Write_Char(temperature%10+0x30);
LCD_Set_XY(0,3);
LCD_Write_Char(smoke/1000+0x30);
LCD_Write_Char((smoke%1000)/100+0x30);
LCD_Write_Char((smoke%100)/10+0x30);
LCD_Write_Char('.');
LCD_Write_Char(smoke%10+0x30);
LCD_Set_XY(0,5);
LCD_Write_Char(fire/1000+0x30);
LCD_Write_Char((fire%1000)/100+0x30);
LCD_Write_Char((fire%100)/10+0x30);
LCD_Write_Char('.');
LCD_Write_Char(fire%10+0x30);
}
void alarm(void)
{
if(temperature/10>=45)
{
temper_flag = 1;
}
else
{
temper_flag = 0;
}
if(smoke/10>=30)
{
smoke_flag = 1;
}
else
{
smoke_flag = 0;
}
if(fire/10>=30)
{
fire_flag = 1;
}
else
{
fire_flag = 0;
}
if(people_flag==1||temper_flag==1||smoke_flag==1||fire_flag==1)
{
if(!cancel_flag)
{
beep = 1;
delay(20);
beep = 0;
delay(20);
led = 1;
}
else
{
beep = 1;
led = 0;
}
}
else
{
beep = 1;
led = 0;
}
}
uchar change(uchar dat)
{
uchar result;
uchar temp_H,temp_L;
temp_H = dat/10;
temp_L = dat%10;
result = temp_H*16+temp_L;
return result;
}
void main(void)
{
uchar channel;
float Rt,temper;
beep = 0;
led = 0;
LCD_Init();
LCD_Write_English(0,0,"temperature");
LCD_Write_English(0,2,"smoke");
LCD_Write_English(0,4,"fire");
init_interrupt();
ex_init();
usart();
while(1)
{
for(channel=0;channel<3;channel++)
{
ad_Value[channel] = ADC0809(channel);
}
for(channel=0;channel<3;channel++)
{
getVoltage[channel] = (float)(ad_Value[channel])/255*5;
}
Rt = getVoltage[0]*4700/(5.0-getVoltage[0]);
temper = 1/(log(Rt/10000)/4050+1/(273.15+25))-273.15;
temperature = (uint)temper*10;
smoke = getVoltage[1]*200;
fire = getVoltage[2]*200;
display();
index = index>2?0:index+1;
switch(index)
{
case 0:SBUF = change((uchar)(fire/10));break;
case 1:SBUF = change((uchar)(temperature/10));break;
case 2:SBUF = change((uchar)(smoke/10));break;
default:break;
}
alarm();
}
}
void timer_T0(void) interrupt 1
{
clk = ~clk;
}
void ex0(void) interrupt 0
{
delay(5);
if(tube==0)
{
people_flag = ~people_flag;
}
}
void usart_int(void) interrupt 4
{
if(RI==1)
{
RI = 0;
receivedata = SBUF;
if(receivedata==0x30)
{
cancel_flag = 1;
}
else
{
cancel_flag = 0;
}
}
else
{
TI = 0;
}
}
设计说明书:
资料清单(提供资料清单所有文件):
|