居家养老监护系统仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
Altium Designer画的居家养老监护系统PCB图如下:(51hei附件中可下载工程文件)
安卓app 用e4a写的:
单片机源程序如下:
- #include "reg52.h" //调用单片机头文件
- #include "delay.h"
- #include "oled.h"
- #include "dht11.h"
- #include "esp8266.h"
- #define uchar unsigned char //无符号字符型 宏定义 变量范围0~255
- #define uint unsigned int //无符号整型 宏定义 变量范围0~65535
- //继电器
- sbit relay1=P1^6;
- sbit relay2=P1^5;
- sbit relay3=P1^4;
- sbit relay4=P1^3;
- sbit relay5=P3^6;
- sbit relay6=P3^7;
- //按键接口
- sbit K0=P2^6; //一键启动
- sbit K1=P2^7; //一键关闭
- sbit K2=P2^5; //R1开/关
- sbit K3=P2^4; //R2开/关
- sbit K4=P2^3; //R3开/关
- sbit K5=P2^2; //R4开/关
- sbit K6=P2^1; //R5开/关
- sbit K7=P2^0; //R6开/关
- //蜂鸣器
- sbit beep=P1^0;
- uchar code table[]="0123456789.";
- uchar T=0,H=0,Receive;
- uchar Recive_table[40]; //用于接收wifi模块反馈到MCU上的数据
- uchar Send_table[10]="0000000000";//前面4位温湿度,后面6位继电器状态,1表示开,0表示关
- void ESP8266_Senddate()
- {
- delay_uint(100);
- ESP8266_Set("AT+CIPSEND=0,10");//发送10个字节
- delay_uint(100);
- ESP8266_Set(Send_table);
- }
- void DHT11_receive() //接收40位的数据
- {
- uchar R_H,R_L,T_H,T_L,RH,RL,TH,TL,revise;
- EA=0; //关闭中断,防止中断影响DHT11出现单片机死机
- DHT11_start();
- if(Data==0)
- {
- while(Data==0); //等待拉高
- DHT11_delay_us(40); //拉高后延时80us
- R_H=DHT11_rec_byte(); //接收湿度高八位
- R_L=DHT11_rec_byte(); //接收湿度低八位
- T_H=DHT11_rec_byte(); //接收温度高八位
- T_L=DHT11_rec_byte(); //接收温度低八位
- revise=DHT11_rec_byte(); //接收校正位
- DHT11_delay_us(25); //结束
- EA=1;
- if((R_H+R_L+T_H+T_L)==revise) //校正
- {
- RH=R_H;
- RL=R_L;
- TH=T_H;
- TL=T_L;
- }
- T=TH;
- H=RH;
- //获取当前温湿度值并显示
- OLED_ShowChar(72,0,T%100/10,16);
- OLED_ShowChar(88,0,T%10,16);
- OLED_ShowChar(72,2,H%100/10,16);
- OLED_ShowChar(88,2,H%10,16);
- //温度
- Send_table[0]=table[T%100/10];
- Send_table[1]=table[T%10];
- //湿度
- Send_table[2]=table[H%100/10];
- Send_table[3]=table[H%10];
- }
- }
- /*****
- 对接收的数据处理
- ******/
- void ESP8266_Recive_Estimate()
- {
- if((Recive_table[0]=='+')&&(Recive_table[1]=='I')&&(Recive_table[2]=='P'))//MCU接收到的数据为+IPD时进入控制
- {
- //一键启动
- if((Recive_table[9]=='a'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- relay1=1;
- relay2=1;
- relay3=1;
- relay4=1;
- relay5=1;
- relay6=1;
- OLED_ShowChinese(24,4,11,16);//继电器1
- OLED_ShowChinese(68,4,11,16);//继电器2
- OLED_ShowChinese(112,4,11,16);//继电器3
- OLED_ShowChinese(24,6,11,16);//继电器4
- OLED_ShowChinese(68,6,11,16);//继电器5
- OLED_ShowChinese(112,6,11,16);//继电器6
- Send_table[4]=Send_table[5]=Send_table[6]=Send_table[7]=Send_table[8]=Send_table[9]=table[1];
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //一键关闭
- if((Recive_table[9]=='b'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- relay1=0;
- relay2=0;
- relay3=0;
- relay4=0;
- relay5=0;
- relay6=0;
- OLED_ShowChinese(24,4,12,16);//继电器1
- OLED_ShowChinese(68,4,12,16);//继电器2
- OLED_ShowChinese(112,4,12,16);//继电器3
- OLED_ShowChinese(24,6,12,16);//继电器4
- OLED_ShowChinese(68,6,12,16);//继电器5
- OLED_ShowChinese(112,6,12,16);//继电器6
- Send_table[4]=Send_table[5]=Send_table[6]=Send_table[7]=Send_table[8]=Send_table[9]=table[0];
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //继电器1控制
- if((Recive_table[9]=='c'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- if((Send_table[4]-'0')==1){Send_table[4]=table[0];OLED_ShowChinese(24,4,12,16);relay1=0;}
- else{Send_table[4]=table[1];OLED_ShowChinese(24,4,11,16);relay1=1;}
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //继电器2控制
- if((Recive_table[9]=='d'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- if((Send_table[5]-'0')==1){Send_table[5]=table[0];OLED_ShowChinese(68,4,12,16);relay2=0;}
- else{Send_table[5]=table[1];OLED_ShowChinese(68,4,11,16);relay2=1;}
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //继电器3控制
- if((Recive_table[9]=='e'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- if((Send_table[6]-'0')==1){Send_table[6]=table[0];OLED_ShowChinese(112,4,12,16);relay3=0;}
- else{Send_table[6]=table[1];OLED_ShowChinese(112,4,11,16);relay3=1;}
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //继电器4控制
- if((Recive_table[9]=='f'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- if((Send_table[7]-'0')==1){Send_table[7]=table[0];OLED_ShowChinese(24,6,12,16);relay4=0;}
- else{Send_table[7]=table[1];OLED_ShowChinese(24,6,11,16);relay4=1;}
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //继电器5控制
- if((Recive_table[9]=='g'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- if((Send_table[8]-'0')==1){Send_table[8]=table[0];OLED_ShowChinese(68,6,12,16);relay5=0;}
- else{Send_table[8]=table[1];OLED_ShowChinese(68,6,11,16);relay5=1;}
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //继电器6控制
- if((Recive_table[9]=='h'))
- {
- //提示音
- beep=1;
- delay_uint(100);
- beep=0;
- if((Send_table[9]-'0')==1){Send_table[9]=table[0];OLED_ShowChinese(112,6,12,16);relay6=0;}
- else{Send_table[9]=table[1];OLED_ShowChinese(112,6,11,16);relay6=1;}
- Recive_table[9]=' ';
- ESP8266_Senddate();
- }
- //APP连接后一直发送
- if((Recive_table[9]=='I'))
- {
- ESP8266_Senddate();
- }
- }
- }
- /****
- 按键控制
- ****/
- void keyscan()
- {
- //一键启动
- if(K0==0)
- {
- delay_uint(10);//延时消抖
- if(K0==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //启动所有继电器
- relay1=1;
- relay2=1;
- relay3=1;
- relay4=1;
- relay5=1;
- relay6=1;
- Send_table[4]=Send_table[5]=Send_table[6]=Send_table[7]=Send_table[8]=Send_table[9]='1';
- OLED_ShowChinese(24,4,11,16);//继电器1
- OLED_ShowChinese(68,4,11,16);//继电器2
- OLED_ShowChinese(112,4,11,16);//继电器3
- OLED_ShowChinese(24,6,11,16);//继电器4
- OLED_ShowChinese(68,6,11,16);//继电器5
- OLED_ShowChinese(112,6,11,16);//继电器6
- while(K0==0);//等待按键释放
- }
- }
- //一键关闭
- if(K1==0)
- {
- delay_uint(10);//延时消抖
- if(K1==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //启动所有继电器
- relay1=0;
- relay2=0;
- relay3=0;
- relay4=0;
- relay5=0;
- relay6=0;
- Send_table[4]=Send_table[5]=Send_table[6]=Send_table[7]=Send_table[8]=Send_table[9]='0';
- OLED_ShowChinese(24,4,12,16);//继电器1
- OLED_ShowChinese(68,4,12,16);//继电器2
- OLED_ShowChinese(112,4,12,16);//继电器3
- OLED_ShowChinese(24,6,12,16);//继电器4
- OLED_ShowChinese(68,6,12,16);//继电器5
- OLED_ShowChinese(112,6,12,16);//继电器6
- while(K1==0);//等待按键释放
- }
- }
- //继电器1
- if(K2==0)
- {
- delay_uint(10);//延时消抖
- if(K2==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //继电器状态翻转
- if(relay1==0){OLED_ShowChinese(24,4,12,16);Send_table[4]='0';}
- else {OLED_ShowChinese(24,4,11,16);Send_table[4]='1';}
- while(K2==0);//等待按键释放
- }
- }
- //继电器2
- if(K3==0)
- {
- delay_uint(10);//延时消抖
- if(K3==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //继电器状态翻转
- relay2=~relay2;
- if(relay2==0){OLED_ShowChinese(68,4,12,16);Send_table[5]='0';}
- else {OLED_ShowChinese(68,4,11,16);Send_table[5]='1';}
- while(K3==0);//等待按键释放
- }
- }
- //继电器3
- if(K4==0)
- {
- delay_uint(10);//延时消抖
- if(K4==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //继电器状态翻转
- relay3=~relay3;
- if(relay3==0){OLED_ShowChinese(112,4,12,16);Send_table[6]='0';}
- else {OLED_ShowChinese(112,4,11,16);Send_table[6]='1';}
- while(K4==0);//等待按键释放
- }
- }
- //继电器4
- if(K5==0)
- {
- delay_uint(10); //延时消抖
- if(K5==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //继电器状态翻转
- relay4=~relay4;
- if(relay4==0){OLED_ShowChinese(24,6,12,16);Send_table[7]='0';}
- else {OLED_ShowChinese(24,6,11,16);Send_table[7]='1';}
- while(K5==0);//等待按键释放
- }
- }
- //继电器5
- if(K6==0)
- {
- delay_uint(10);//延时消抖
- if(K6==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //继电器状态翻转
- relay5=~relay5;
- if(relay5==0){OLED_ShowChinese(68,6,12,16);Send_table[8]='0';}
- else {OLED_ShowChinese(68,6,11,16);Send_table[8]='1';}
- while(K6==0);//等待按键释放
- }
- }
- //继电器6
- if(K7==0)
- {
- delay_uint(10);//延时消抖
- if(K7==0)
- {
- //按键提示音
- beep=1;
- delay_uint(100);
- beep=0;
- //继电器状态翻转
- relay6=~relay6;
- if(relay6==0){OLED_ShowChinese(112,6,12,16);Send_table[9]='0';}
- else {OLED_ShowChinese(112,6,11,16);Send_table[9]='1';}
- while(K7==0);//等待按键释放
- }
- }
-
- }
- /*****
- 系统初始化函数
- ****/
- void System_Init()
- {
- beep=0;//关闭蜂鸣器
- //关闭所有继电器
- relay1=0;
- relay2=0;
- relay3=0;
- relay4=0;
- relay5=0;
- relay6=0;
- //OLED初始化
- OLED_Init();
- //开机显示
- OLED_ShowChinese(10,0,0,16);
- OLED_ShowChinese(28,0,1,16);
- OLED_ShowChinese(42,0,2,16);
- OLED_ShowChinese(60,0,3,16);
- OLED_ShowChinese(78,0,4,16);
- OLED_ShowChar(96,0,11,16);//!
- OLED_ShowChinese(10,3,5,16);
- OLED_ShowChinese(28,3,6,16);
- OLED_ShowChinese(42,3,7,16);
- OLED_ShowChar(60,3,24,16);//.
- OLED_ShowChar(78,3,24,16);//.
- OLED_ShowChar(96,3,24,16);//.
- //ESP8266模块初始化
- ESP8266_Init();
- OLED_Clear();//清屏
- //显示温度
- OLED_ShowChinese(20,0,8,16);
- OLED_ShowChinese(38,0,9,16);
- OLED_ShowChar(56,0,26,16);
- OLED_ShowChar(72,0,T%100/10,16);
- OLED_ShowChar(88,0,T%10,16);
- OLED_ShowChar(102,0,35,16);
- OLED_ShowChar(110,0,95,16);
- //显示湿度
- OLED_ShowChinese(20,2,10,16);
- OLED_ShowChinese(38,2,9,16);
- OLED_ShowChar(56,2,26,16);
- OLED_ShowChar(72,2,H%100/10,16);
- OLED_ShowChar(88,2,H%10,16);
- OLED_ShowChar(102,2,15,16);
- //显示继电器状态、继电器1
- OLED_ShowChar(0,4,50,16);
- OLED_ShowChar(8,4,1,16);
- OLED_ShowChar(16,4,26,16);
- OLED_ShowChinese(24,4,12,16);
- //继电器2
- OLED_ShowChar(44,4,50,16);
- OLED_ShowChar(52,4,2,16);
- OLED_ShowChar(60,4,26,16);
- OLED_ShowChinese(68,4,12,16);
- //继电器3
- OLED_ShowChar(88,4,50,16);
- OLED_ShowChar(96,4,3,16);
- OLED_ShowChar(104,4,26,16);
- OLED_ShowChinese(112,4,12,16);
- //继电器4
- OLED_ShowChar(0,6,50,16);
- OLED_ShowChar(8,6,4,16);
- OLED_ShowChar(16,6,26,16);
- OLED_ShowChinese(24,6,12,16);
- //继电器5
- OLED_ShowChar(44,6,50,16);
- OLED_ShowChar(52,6,5,16);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
上图资料51hei附件下载 程序Keil5,仿真Proteus8.8,ad10 PCB:
居家养老监护系统.7z
(2.93 MB, 下载次数: 82)
|