本設(shè)計:
仿真版本:proteus 8.9
程序編譯器:keil 4
設(shè)計編號:C0040
功能介紹:
以提高家居生活的安全性、舒適度、人性化為目的,設(shè)計智能家居監(jiān)控系統(tǒng)。
(1)設(shè)計必須實現(xiàn)家居溫度、煤氣泄漏、外人闖入、火災(zāi)(煙霧)的全部檢測;
(2)各檢測節(jié)點可通過無線方式連接到主機,檢測到危險信號后,主機采用聲光報警或遠程報警;
(3)系統(tǒng)具有檢測靈敏、報警及時、性價比高等特點;
(4)拓展部分:增加檢測項目并具有可行性,除環(huán)境檢測外也可增加人體信號(心率、體溫)檢測等。
分析:為實現(xiàn)溫度檢測、煤氣和煙霧等氣體檢測、監(jiān)控外人闖入等功能,采用NTC熱敏電阻、MQ2氣體檢測傳感器、磁控開關(guān)等傳感器。
資料下載鏈接(可點擊):
仿真圖(提供源文件):
源程序(提供源文件)
#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;//定義發(fā)送數(shù)據(jù)個數(shù)
uchar ad_Value[3];//定義AD采集數(shù)據(jù)
float getVoltage[3];//定義電壓采集數(shù)值
uchar receivedata;//定義串口接收數(shù)據(jù)
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;
}
//顯示函數(shù)
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);
}
//報警函數(shù)
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;
}
}
//數(shù)據(jù)格式轉(zhuǎn)換
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測溫相關(guān)參量
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)
{
//采集數(shù)據(jù)
for(channel=0;channel<3;channel++)
{
ad_Value[channel] = ADC0809(channel);
}
//處理數(shù)據(jù)
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;
//顯示數(shù)據(jù)
display();
//發(fā)送數(shù)據(jù)
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;
}
//報警系統(tǒng)
alarm();
}
}
void timer_T0(void) interrupt 1
{
clk = ~clk;
}
void ex0(void) interrupt 0
{
delay(5);
if(tube==0)//干簧管被觸發(fā)
{
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;
}
}
設(shè)計說明書:
資料清單(提供資料清單所有文件):