找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3697|回复: 4
打印 上一主题 下一主题
收起左侧

我的基于51单片机WIFI温湿度控制系统设计 含有码源,原理图和文档以及焊接图

[复制链接]
跳转到指定楼层
楼主
ID:333909 发表于 2018-5-27 11:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我最近花费很长时间做的
基于51单片机WIFI温湿度控制系统设计,

附件里面包含了WIFI温湿度控制系统的单片机的码源,
以及原理图和焊接图,
希望大家多多指教

新建 Microsoft Word 文档 (3).docx (17.61 KB, 下载次数: 66)
焊接图.pdf (38.87 KB, 下载次数: 33)
元件清单.doc (28 KB, 下载次数: 26)
原理图.pdf (51.59 KB, 下载次数: 69)


  1. #include "reg52.h"
  2. #include "uart.h"
  3. #include "stdio.h"

  4. #include "dht11.h"  
  5. #include "string.h"
  6. //管脚声明
  7. unsigned char Timer0_count;
  8. unsigned char Timer0_miao;
  9. unsigned char miao1;
  10. unsigned char flag_init;
  11. unsigned char RsPoint;
  12. unsigned char xdata RsBuf[100];
  13. sbit LED2 = P1^2;        //灯光控制输出
  14. sbit LED3 = P1^3;        //灯光控制输出
  15. sbit LED4 = P1^4;        //灯光控制输出
  16. sbit LED1 = P1^1;        //灯光控制输出
  17. unsigned char Key_num;
  18. unsigned char Flag_rec;
  19. unsigned char Rec_stop;
  20. #include "lcd.h"




  21. void main()
  22. {
  23.         char *str2="AT+CIPSEND=14\r\n";
  24.         unsigned char i;

  25.         memset(&RsBuf[1],' ',18);
  26.     Uart_init();
  27.     lcd_init();
  28.         delay(3000);
  29.         SendString("+++");
  30.         delay(500);
  31.         SendString("+++\r\n");
  32.         delay(500);
  33. //        write_1602com(0xc0);
  34. //        for(i=0;i<16;i++)
  35. //        write_1602dat(RsBuf[i+2]);
  36.         Rec_stop=0;
  37.        
  38.           memset(&RsBuf[1],' ',18);
  39.         SendString("AT+CWMODE=1\r\n");
  40.         write_1602com(0x01);
  41.         write_string(0x80,"AT+CWMODE=1     ",0);
  42.         while(Rec_stop==0) ;
  43.         Rec_stop=0;
  44. //        write_1602com(0xc0);
  45. //        delay(1);
  46. //        for(i=0;i<2;i++)
  47. //        write_1602dat(RsBuf[i+2]);
  48.         delay(2000);

  49.           memset(&RsBuf[1],' ',18);
  50.         SendString("AT+RST\r\n");
  51.         write_1602com(0x01);
  52.     write_string(0x80,"AT+RST          ",0);
  53.         while(Rec_stop==0&&RsBuf[0]!='W');
  54.         Rec_stop=0;
  55. //        write_1602com(0xc0);
  56. //        for(i=0;i<16;i++)
  57. //        write_1602dat(RsBuf[i+2]);
  58.            delay(3000);

  59.           memset(&RsBuf[1],' ',18);
  60.     SendString("ATE0\r\n");
  61.         write_string(0x80,"ATE0            ",0);
  62.         write_string(0xc0,"                ",0);
  63.         while(Rec_stop==0) ;
  64.         Rec_stop=0;
  65. //        write_1602com(0xc0);
  66. //        delay(1);
  67. //        for(i=0;i<2;i++)
  68.         write_1602dat(RsBuf[i+2]);
  69.         delay(2000);

  70.            memset(&RsBuf[1],' ',18);
  71.         SendString("ATE0\r\n");
  72.         write_1602com(0x01);
  73.         write_string(0x80,"ATE0            ",0);
  74.         while(Rec_stop==0) ;
  75.         Rec_stop=0;
  76. //        write_1602com(0xc0);
  77. //        delay(1);
  78. //        for(i=0;i<2;i++)
  79. //        write_1602dat(RsBuf[i+2]);
  80.                 delay(2000);

  81.         memset(&RsBuf[1],' ',18);
  82.     SendString("AT+CIPMUX=0\r\n");
  83.         write_1602com(0x01);
  84.     write_string(0x80,"AT+CIPMUX=0      ",0);
  85.         while(Rec_stop==0);
  86.         Rec_stop=0;
  87. //        write_1602com(0xc0);
  88. //        for(i=0;i<2;i++)
  89. //        write_1602dat(RsBuf[i+2]);
  90.            delay(100);

  91.             memset(&RsBuf[1],' ',18);
  92.         SendString("AT+CIPSTART=\"TCP\",\"114.215.204.246\",9999\r\n");
  93.         write_1602com(0x01);
  94.     write_string(0x80,"AT+CISTART=TCP   ",0);
  95.         while(Rec_stop==0&&RsBuf[2]=='O');
  96.         Rec_stop=0;
  97. //        write_1602com(0xc0);
  98. //        for(i=0;i<2;i++)
  99. //        write_1602dat(RsBuf[i+2]);
  100.         delay(2000);


  101.             memset(&RsBuf[1],' ',18);
  102.         SendString("AT+CIPMODE=1\r\n");
  103.         write_1602com(0x01);
  104.     write_string(0x80,"AT+CIPMODE=1     ",0);
  105.         while(Rec_stop==0);
  106.         Rec_stop=0;
  107. //        write_1602com(0xc0);
  108. //        for(i=0;i<2;i++)
  109. //        write_1602dat(RsBuf[i+2]);
  110.         delay(2000);

  111.         RsPoint=0;
  112.         memset(&RsBuf[1],' ',18);
  113.     SendString("AT+CIPSEND\r\n");
  114.         write_1602com(0x01);
  115.     write_string(0x80,"AT+CIPSEND       ",0);
  116.         while(RsPoint==0);
  117. //        write_1602com(0xc0);
  118. //        for(i=0;i<16;i++)
  119. //        write_1602dat(RsBuf[i]);
  120.            delay(2000);
  121.         SendString("AT+CWJAP=\"wodewifi\",\"nidemima\"\r\n");                       
  122.          //在这里填入你的路由器名称和密码 分别替代wodewifi和 nidemima 双引号和斜杠不能删除
  123.         delay(5000);
  124.        
  125.         write_string(0x80,"Te:   C   Hu:  %",0);                //第一行显示字符串
  126.         write_string(0xc0,"STATUS:0000     ",0);                //第二行显示字符串
  127.         write_1602com(0x85);                                                        //选中位置
  128.         write_1602dat(0xdf);                                                        //显示摄氏度的°

  129.         while(1)
  130.         {
  131.                   if(FlagStart==1)
  132.                 {
  133.                      TR0=0;
  134.              RH();
  135.                          FlagStart = 0;
  136.                          write_1602com(0x83);                                                  //指定第一行第三个位置
  137.                          write_1602dat(temperature%100/10+0x30);          //显示温度的十位
  138.                          write_1602dat(temperature%100%10+0x30);          //显示温度个位
  139.                          write_1602com(0x8d);                                                  //选中第一行第十三个位置
  140.                          write_1602dat(humidity%100/10+0x30);                  //显示湿度十位
  141.                          write_1602dat(humidity%100%10+0x30);                  //显示湿度个位
  142.                          SendString("{\"UN\":\"yhdifiot024@163.com\",\"VER\":\"A1.1\",\"ID\":\"234103\",\"MAC\":\"18fe35f1cd4a\",\"TP\":\"");
  143.                          //784551388@qq.com是账号          234100是ID
  144.                  SendASC(temperature%100/10+0x30);          //1
  145.                  SendASC(temperature%10+0x30);                //1
  146.                  SendString("\",\"HM\":\"");                   //  8
  147.                  SendASC(humidity%100/10+0x30);          //1
  148.                  SendASC(humidity%10+0x30);                //1
  149.                  SendString("\",\"SOC\":\"99\",\"RET\":\"1\"}\r\n");         
  150.                          TR0=1;
  151.                          Timer0_count=0;
  152.                          Timer0_miao=0;
  153.                 }
  154.          
  155.       
  156.                 write_1602com(0xc7);                         //选中第二行第七个位置
  157.                 if(LED1)                                                 //如果LED1等于1
  158.             write_1602dat('0');                                 //显示0
  159.                 else                                                         //LED1不等于1
  160.                 write_1602dat('1');                                 //显示1
  161.                 if(LED2)
  162.             write_1602dat('0');
  163.                 else
  164.                 write_1602dat('2');
  165.                 if(LED3)
  166.             write_1602dat('0');
  167.                 else
  168.                 write_1602dat('3');
  169.                 if(LED4)
  170.             write_1602dat('0');
  171.                 else
  172.                 write_1602dat('4');

  173.                 delay(100);
  174.         }

  175.    
  176. }

  177. //  通讯中断接收程序   中断函数无返回值
  178.   void uart_rx(void)  interrupt 4   //放在这里 和放在main()里面是一样的
  179. {
  180.    
  181.         unsigned char dat;
  182.     if(RI)                         //是否接收中断
  183.     {
  184.      RI=0;
  185.          dat = SBUF;
  186.          if(SBUF=='\r')
  187.          {
  188.            RsPoint=0;
  189.            Rec_stop=1;
  190.           }
  191.           RsBuf[RsPoint]=SBUF;
  192.           RsPoint++;
  193.          if(Flag_rec==1)
  194.          {
  195.                  switch (Key_num)
  196.                  {
  197.                   case 'A': if(dat=='0')LED1=0; else LED1=1;break;
  198.                   case 'B': if(dat=='0')LED2=0; else LED2=1; break;
  199.                   case 'C': if(dat=='0')LED3=0; else LED3=1; break;
  200.                   case 'D': if(dat=='0')LED4=0; else LED4=1; break;
  201.                  }
  202.                  Flag_rec=0;
  203.      }  
  204.          if(dat=='A'||dat=='B'||dat=='C'||dat=='D')
  205.          {
  206.           Flag_rec=1;
  207.           Key_num=dat;
  208.          }
  209.         }

  210. }

  211. void Timer0_ISR (void) interrupt 1 using 0
  212. {
  213.   TH0=0x4c;
  214.   TL0=0x00;
  215.   Timer0_count++;
  216.   if(Timer0_count>=20)
  217.   {
  218.    Timer0_count=0;
  219.    Timer0_miao++;

  220.    if(Timer0_miao>=2)
  221.    {
  222.     Timer0_miao=0;
  223.         FlagStart=1;
  224.    }
  225.   }
  226. }  
复制代码




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2018-5-27 18:21 | 只看该作者
楼主能分享完整的源码资料吗?
回复

使用道具 举报

板凳
ID:447221 发表于 2018-12-26 20:06 | 只看该作者
谢谢楼主分享
回复

使用道具 举报

地板
ID:456683 发表于 2018-12-27 18:38 | 只看该作者
这个是用DHT11测湿度嘛
回复

使用道具 举报

5#
ID:540448 发表于 2020-9-18 23:28 来自手机 | 只看该作者
这个不完整?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表