赞
踩
本设计:
仿真版本:proteus 8.9
程序编译器:keil 5
功能介绍:
以提高家居生活的安全性、舒适度、人性化为目的,设计智能家居监控系统。
(1)设计必须实现家居温度、煤气泄漏、外人闯入、火灾(烟雾)的全部检测;
(2)各检测节点可通过无线方式连接到主机,检测到危险信号后,主机采用声光报警或远程报警;
(3)系统具有检测灵敏、报警及时、性价比高等特点;
(4)拓展部分:增加检测项目并具有可行性,除环境检测外也可增加人体信号(心率、体温)检测等。
分析:为实现温度检测、煤气和烟雾等气体检测、监控外人闯入等功能,采用NTC热敏电阻、MQ2气体检测传感器、磁控开关等传感器。
资料下载链接(可点击):
adc0809驱动文件 https://download.csdn.net/download/C_say_easy_to_me/86515019
5110显示屏驱动文件 https://download.csdn.net/download/C_say_easy_to_me/86515018
完全程序文件:https://download.csdn.net/download/C_say_easy_to_me/86515026
仿真图(提供源文件):https://download.csdn.net/download/C_say_easy_to_me/86515025
源程序:
#include "lcd5110.h" #include "adc0809.h" #include <math.h> float getVoltage[3];//定义电压采集数值 uint temperature;//温度 uint smoke;//煤气浓度 uint fire;//烟雾浓度 uchar index;//定义发送数据个数 uchar ad_Value[3];//定义AD采集数据 uchar receivedata;//定义串口接收数据 sbit tube = P3^2;//干簧管 sbit beep = P3^6;//蜂鸣器 sbit led = P3^7;//LED灯 bit people_flag;//外人闯入标志位 bit temper_flag;//温度异常标志位 bit smoke_flag;//煤气浓度异常标志位 bit fire_flag;//烟雾浓度异常标志位 bit cancel_flag;//取消报警标志位 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;// 波特率 9600 向TH1高8位写入初值 TL1 = 0xfd;//向TL1低8位写入初值 TR1 = 1;//启动定时器T1 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; } } //数据格式转换 void port(uchar dat) { uchar temp_H,temp_L; temp_H = dat/10; temp_L = dat%10; SBUF=(temp_H+0x30); delay(1); SBUF=(temp_L+0x30); delay(1); SBUF=0x20; } void main(void) { float Rt,temper;//NTC测温相关参量 uchar channel;//定义ADC通道号 beep = 0;//声光报警初始化 led = 0; LCD_init();//显示初始化 /*参数显示*/ LCD_write_english_string(0,0,"temperature"); LCD_write_english_string(0,2,"smoke"); LCD_write_english_string(0,4,"fire"); init_interrupt();//定时器初始化 ex_init();//外部中断初始化 usart();//串口初始化 while(1) { //采集数据 for(channel=0;channel<3;channel++) { ad_Value[channel] = AD(channel); } //处理数据 for(channel=0;channel<3;channel++) { getVoltage[channel] = (ad_Value[channel]*1.0)/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: port((uchar)(fire/10));break; case 1: port((uchar)(temperature/10));break; case 2: port((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; } }
lcd5110.h
/* 2007-2-1 12:06 nokia 5110 driver program for 51 mcu by zl0801 zhaoliang0801@gmail.com */ #include <reg52.h> // pin define for n5110lcd_8key board // change this if your hardware changed! sbit SCLK = P0^2; // pin 2 header 5 sbit SDIN = P0^3; // pin 3 header 4 sbit LCD_DC = P0^1; // pin 4 header 3 sbit LCD_CE = P0^0; // pin 5 header 2 sbit LCD_RST = P0^4; // pin 9 header 1 void LCD_init(void); void LCD_clear(void); void LCD_move_chinese_string(unsigned char X, unsigned char Y, unsigned char T); void LCD_write_english_string(unsigned char X,unsigned char Y,char *s); //void LCD_write_chinese_string(unsigned char X, unsigned char Y, // unsigned char ch_with,unsigned char num, // unsigned char line,unsigned char row); void chinese_string(unsigned char X, unsigned char Y, unsigned char T); void LCD_write_char(unsigned char c); //void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map, // unsigned char Pix_x,unsigned char Pix_y); void LCD_write_byte(unsigned char dat, unsigned char dc); void LCD_set_XY(unsigned char X, unsigned char Y); //void delay_1us(void); extern code unsigned char font6x8[][6]; extern void delay(unsigned char num); //extern code unsigned char write_chinese[][24];
adc0809.h
#include <reg52.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int // adc0809模块接线 sbit STR=P1^0; //单片机P1.0接模块STR引脚, 启动转换信号 sbit EOC=P1^1; //单片机P1.1接模块EOC, 转换结束信号,高电平有效 sbit OE=P1^2; //单片机P1.2接模块OE,输出允许信号,高电平有效 sbit CLK=P1^3; //单片机P1.3接CLK ,ADC0809时钟,输入50-800KHZ的频率 //一般选用500K #define adc0809_data P2// ADC0809模块的D0-D7分别接P2.0-P2.7(已改动) /*地址选择 A 接H B 接H C 接L 选择通到IN3,当然也可以通过软件设置地址 REF+ 接VCC REF- 接GND 这样 AD=256*(VIN-(VREF-))/(VREF+)-(VREF-) (VREF+)=5V; (VREF-)=0V; AD=256*VIN/5 所以IN3口的电压VIN=AD*5/256; */ //==============LCD1602接口连接方法===================== /*----------------------------------------------------- |DB0-----P0.0 | DB4-----P0.4 | RW-------P2.3 | |DB1-----P0.1 | DB5-----P0.5 | RS-------P2.4 | |DB2-----P0.2 | DB6-----P0.6 | E--------P2.2 | |DB3-----P0.3 | DB7-----P0.7 | ---------------------------------------------------*/ //================================================*/ //#define LCM_Data P0 //LCD1602数据接口 //#define Busy 0x80 //用于检测LCM状态字中的Busy标识 //sbit LCM_RW = P2^3; //读写控制输入端,LCD1602的第五脚 //sbit LCM_RS = P2^4; //寄存器选择输入端,LCD1602的第四脚 //sbit LCM_E = P2^2; //使能信号输入端,LCD1602的第6脚 //**************函数声明*************************************** //void WriteDataLCM (uchar WDLCM);//LCD模块写数据 //void WriteCommandLCM (uchar WCLCM,BuysC); //LCD模块写指令 //uchar ReadStatusLCM(void);//读LCD模块的忙标 //void DisplayOneChar(uchar X,uchar Y,uchar ASCII);//在第X+1行的第Y+1位置显示一个字符 //void LCMInit(void);//LCD初始 //void delayms(uint ms);//1MS基准延时程序 void delay(uchar i); //延时函数2 //void DisplayListChar(uchar X,uchar Y,uchar delayms, uchar code *DData); //void judge_xianshi(void);//显示处理程序 //void init();//系统初始化设置 void choose(unsigned char x);//通道选择 uchar AD(uchar channel);//读取AD数据
字模文件 bmp_pixel.h:
/*------------------------------------------------------------------------------ ; 源文件 / 文字 : AVR ; 宽×高(像素): 40×24 ; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/120字节 ; 数据转换日期 : 2004-8-13 ------------------------------------------------------------------------------*/ code unsigned char AVR_bmp[]= { /*-- 调入了一幅图像:C:\Documents and Settings\armok\桌面\1.bmp --*/ /*-- 宽度x高度=60x47 --*/ /*0x00,0x00,0x00,0x00,0x80,0xE0,0xFC,0xFF,0xFF,0xFF,0x7F,0xFF,0xFE,0xFC,0xF0,0xC1, 0x0F,0x7F,0xFF,0xFF,0xFE,0xF0,0xC0,0x00,0x00,0x00,0xC0,0xF8,0xFE,0xFF,0xFF,0x3F, 0x07,0xC1,0xF0,0xFE,0xFF,0xFF,0xFF,0x1F,0x07,0x8F,0xCF,0xFF,0xFF,0xFF,0xFE,0xFC, 0x00,0x80,0xF0,0xFC,0xFF,0xFF,0xFF,0x7F,0x7F,0x78,0x78,0x79,0x7F,0x7F,0xFF,0xFF, 0xFC,0xF0,0xC1,0x07,0x1F,0xFF,0xFF,0xFE,0xFC,0xFF,0xFF,0xFF,0x1F,0x07,0xC1,0xF0, 0xFE,0xFF,0xFF,0x3F,0x0F,0x0F,0x7F,0xFF,0xFF,0xFF,0xFF,0xE7,0x07,0x03,0x01,0x00, 0x02,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0x03,0x03,0x03,0x03,0x00,0x00,0x03,0x1F,0x3F,0x1F,0x07,0x00,0x00,0x02,0x03,0x03, 0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x40, 0x20,0x00,0x10,0x10,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x10,0x10,0x00, 0x20,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x0C,0x02,0x01,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x0C,0x70,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00, 0x80,0xC0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0, 0xE0,0xF0,0xF0,0xF0,0xF0,0xE0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x7F,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00, 0x18,0x60,0x83,0x87,0x87,0x87,0x07,0x03,0x03,0x03,0x01,0x40,0xF0,0xF0,0xF0,0xF0, 0xF0,0x40,0x01,0x03,0x03,0x03,0x07,0x87,0x87,0x87,0x83,0x60,0x18,0x00,0x07,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x1F,0x27,0x48,0x88,0x88,0x88,0x88,0x88,0x48, 0x48,0x48,0x88,0x88,0x88,0x88,0x88,0x48,0x27,0x1F,0x00,0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x02,0x04,0x04,0x08,0x00,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x08,0x04,0x04,0x02,0x03,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
英文字模:
// 6 x 8 font // 1 pixel space at left and bottom // index = ASCII - 32 code unsigned char font6x8[][6]= { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // " { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // % { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // & { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // , { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // - { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // . { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // / { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // : { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ; { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // < { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // = { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // > { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55 { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines };
主程序
参考:https://stm32.blog.csdn.net/article/details/125711972
通道选择:
参考:https://blog.csdn.net/m0_53048901/article/details/117969595
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。