51单片机控制智能家居监控系统设计仿真
本設計:
仿真版本: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;//啟動定時器T1EA = 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 zl0801zhaoliang0801@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 1void 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 接HC 接L 選擇通到IN3,當然也可以通過軟件設置地址REF+ 接VCCREF- 接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
總結
以上是生活随笔為你收集整理的51单片机控制智能家居监控系统设计仿真的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySql desc 的三种用法
- 下一篇: 天才制造者:独行侠、科技巨头和AI|深度