本设计:
仿真版本: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;//LED灯
uint temperature;//温度
uint smoke;//煤气浓度
uint fire;//烟雾浓度
uchar index;//定义发送数据个数
uchar ad_Value[3];//定义AD采集数据
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;//定义ADC通道号
float Rt,temper;//NTC测温相关参量
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;
}
}
设计说明书:
资料清单(提供资料清单所有文件):
阅读全文