这是我最近花费很长时间做的 基于51单片机WIFI温湿度控制系统设计,
附件里面包含了WIFI温湿度控制系统的单片机的码源,
以及原理图和焊接图,
希望大家多多指教
新建 Microsoft Word 文档 (3).docx
(17.61 KB, 下载次数: 66)
焊接图.pdf
(38.87 KB, 下载次数: 33)
元件清单.doc
(28 KB, 下载次数: 26)
原理图.pdf
(51.59 KB, 下载次数: 70)
- #include "reg52.h"
- #include "uart.h"
- #include "stdio.h"
-
- #include "dht11.h"
- #include "string.h"
- //管脚声明
- unsigned char Timer0_count;
- unsigned char Timer0_miao;
- unsigned char miao1;
- unsigned char flag_init;
- unsigned char RsPoint;
- unsigned char xdata RsBuf[100];
- sbit LED2 = P1^2; //灯光控制输出
- sbit LED3 = P1^3; //灯光控制输出
- sbit LED4 = P1^4; //灯光控制输出
- sbit LED1 = P1^1; //灯光控制输出
- unsigned char Key_num;
- unsigned char Flag_rec;
- unsigned char Rec_stop;
- #include "lcd.h"
-
-
- void main()
- {
- char *str2="AT+CIPSEND=14\r\n";
- unsigned char i;
-
- memset(&RsBuf[1],' ',18);
- Uart_init();
- lcd_init();
- delay(3000);
- SendString("+++");
- delay(500);
- SendString("+++\r\n");
- delay(500);
- // write_1602com(0xc0);
- // for(i=0;i<16;i++)
- // write_1602dat(RsBuf[i+2]);
- Rec_stop=0;
-
- memset(&RsBuf[1],' ',18);
- SendString("AT+CWMODE=1\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CWMODE=1 ",0);
- while(Rec_stop==0) ;
- Rec_stop=0;
- // write_1602com(0xc0);
- // delay(1);
- // for(i=0;i<2;i++)
- // write_1602dat(RsBuf[i+2]);
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("AT+RST\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+RST ",0);
- while(Rec_stop==0&&RsBuf[0]!='W');
- Rec_stop=0;
- // write_1602com(0xc0);
- // for(i=0;i<16;i++)
- // write_1602dat(RsBuf[i+2]);
- delay(3000);
- memset(&RsBuf[1],' ',18);
- SendString("ATE0\r\n");
- write_string(0x80,"ATE0 ",0);
- write_string(0xc0," ",0);
- while(Rec_stop==0) ;
- Rec_stop=0;
- // write_1602com(0xc0);
- // delay(1);
- // for(i=0;i<2;i++)
- write_1602dat(RsBuf[i+2]);
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("ATE0\r\n");
- write_1602com(0x01);
- write_string(0x80,"ATE0 ",0);
- while(Rec_stop==0) ;
- Rec_stop=0;
- // write_1602com(0xc0);
- // delay(1);
- // for(i=0;i<2;i++)
- // write_1602dat(RsBuf[i+2]);
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPMUX=0\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CIPMUX=0 ",0);
- while(Rec_stop==0);
- Rec_stop=0;
- // write_1602com(0xc0);
- // for(i=0;i<2;i++)
- // write_1602dat(RsBuf[i+2]);
- delay(100);
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPSTART=\"TCP\",\"114.215.204.246\",9999\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CISTART=TCP ",0);
- while(Rec_stop==0&&RsBuf[2]=='O');
- Rec_stop=0;
- // write_1602com(0xc0);
- // for(i=0;i<2;i++)
- // write_1602dat(RsBuf[i+2]);
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPMODE=1\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CIPMODE=1 ",0);
- while(Rec_stop==0);
- Rec_stop=0;
- // write_1602com(0xc0);
- // for(i=0;i<2;i++)
- // write_1602dat(RsBuf[i+2]);
- delay(2000);
- RsPoint=0;
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPSEND\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CIPSEND ",0);
- while(RsPoint==0);
- // write_1602com(0xc0);
- // for(i=0;i<16;i++)
- // write_1602dat(RsBuf[i]);
- delay(2000);
- SendString("AT+CWJAP=\"wodewifi\",\"nidemima\"\r\n");
- //在这里填入你的路由器名称和密码 分别替代wodewifi和 nidemima 双引号和斜杠不能删除
- delay(5000);
-
- write_string(0x80,"Te: C Hu: %",0); //第一行显示字符串
- write_string(0xc0,"STATUS:0000 ",0); //第二行显示字符串
- write_1602com(0x85); //选中位置
- write_1602dat(0xdf); //显示摄氏度的°
- while(1)
- {
- if(FlagStart==1)
- {
- TR0=0;
- RH();
- FlagStart = 0;
- write_1602com(0x83); //指定第一行第三个位置
- write_1602dat(temperature%100/10+0x30); //显示温度的十位
- write_1602dat(temperature%100%10+0x30); //显示温度个位
- write_1602com(0x8d); //选中第一行第十三个位置
- write_1602dat(humidity%100/10+0x30); //显示湿度十位
- write_1602dat(humidity%100%10+0x30); //显示湿度个位
- SendString("{\"UN\":\"yhdifiot024@163.com\",\"VER\":\"A1.1\",\"ID\":\"234103\",\"MAC\":\"18fe35f1cd4a\",\"TP\":\"");
- //784551388@qq.com是账号 234100是ID
- SendASC(temperature%100/10+0x30); //1
- SendASC(temperature%10+0x30); //1
- SendString("\",\"HM\":\""); // 8
- SendASC(humidity%100/10+0x30); //1
- SendASC(humidity%10+0x30); //1
- SendString("\",\"SOC\":\"99\",\"RET\":\"1\"}\r\n");
- TR0=1;
- Timer0_count=0;
- Timer0_miao=0;
- }
-
-
- write_1602com(0xc7); //选中第二行第七个位置
- if(LED1) //如果LED1等于1
- write_1602dat('0'); //显示0
- else //LED1不等于1
- write_1602dat('1'); //显示1
- if(LED2)
- write_1602dat('0');
- else
- write_1602dat('2');
- if(LED3)
- write_1602dat('0');
- else
- write_1602dat('3');
- if(LED4)
- write_1602dat('0');
- else
- write_1602dat('4');
- delay(100);
- }
-
-
- }
- // 通讯中断接收程序 中断函数无返回值
- void uart_rx(void) interrupt 4 //放在这里 和放在main()里面是一样的
- {
-
- unsigned char dat;
- if(RI) //是否接收中断
- {
- RI=0;
- dat = SBUF;
- if(SBUF=='\r')
- {
- RsPoint=0;
- Rec_stop=1;
- }
- RsBuf[RsPoint]=SBUF;
- RsPoint++;
- if(Flag_rec==1)
- {
- switch (Key_num)
- {
- case 'A': if(dat=='0')LED1=0; else LED1=1;break;
- case 'B': if(dat=='0')LED2=0; else LED2=1; break;
- case 'C': if(dat=='0')LED3=0; else LED3=1; break;
- case 'D': if(dat=='0')LED4=0; else LED4=1; break;
- }
- Flag_rec=0;
- }
- if(dat=='A'||dat=='B'||dat=='C'||dat=='D')
- {
- Flag_rec=1;
- Key_num=dat;
- }
- }
- }
- void Timer0_ISR (void) interrupt 1 using 0
- {
- TH0=0x4c;
- TL0=0x00;
- Timer0_count++;
- if(Timer0_count>=20)
- {
- Timer0_count=0;
- Timer0_miao++;
-
- if(Timer0_miao>=2)
- {
- Timer0_miao=0;
- FlagStart=1;
- }
- }
- }
复制代码
|