全新论坛MCU智学网上线,欢迎访问新论坛!稀缺资源、技术干货、参考设计、原厂资料尽在MCU智学网
更新自动建库工具PCB Footprint Expert 2023.13 Pro / Library Expert 破解版

单片机连接ESP8266点亮LED问题

[复制链接]
2320 0

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
正在学习ESP8266或者已经会了的坛友们,想请问如下代码有没有问题呢?
单片机和ESP8266连接正常,但是执行代码后,用手机或者电脑网络调试助手给ESP发1,LED只是闪烁一下,而且收不到ESP发送的打开和关闭,这是为什么呢?
  1. #include<reg52.h>
  2. #include<intrins.h>       
  3. #define uchar unsigned char
  4. #define uint unsigned int   
  5. sbit led=P1^0;
  6. uchar Receive,i;                             
  7. uint n;
  8. uchar Recive_table[15];  
  9. void ms_delay(uint t)
  10. {
  11.       uint i,j;
  12.       for(i=t;i>0;i--)
  13.        for(j=110;j>0;j--);
  14. }

  15. void us_delay(uchar t)
  16. {
  17.       while(t--);
  18. }


  19. void Uart_Init()
  20. {
  21.       SCON=0x50;     
  22.       PCON=0x00;     
  23.       TMOD=0x21;   
  24.       TH1=0xfd;
  25.       TL1=0xfd;
  26.       EA=1;                           
  27.       ES=1;                             
  28.       TR1=1;   
  29. }

  30. void Send_Uart(uchar value)
  31. {
  32.       ES=0;         
  33.       TI=0;         
  34.       SBUF=value;     
  35.       while(TI==0);   
  36.       TI=0;         
  37.       ES=1;         
  38. }

  39. void ESP8266_Set(uchar *puf)               
  40. {

  41.       while(*puf!='\0')   
  42.       {
  43.            Send_Uart(*puf);  
  44.            us_delay(5);
  45.            puf++;      
  46.       }
  47.       us_delay(5);
  48.       Send_Uart('\r');
  49.       us_delay(5);
  50.       Send_Uart('\n');   
  51.       
  52. }   

  53. void ESP8266_Sent(uchar *puf)                  
  54. {
  55.       ESP8266_Set("AT+CIPSEND=0,2");
  56.       while(*puf!='\0')   
  57.       {
  58.            Send_Uart(*puf);   
  59.            us_delay(5);
  60.            puf++;      
  61.       }
  62.       us_delay(5);
  63.       Send_Uart('\n');   
  64.       ms_delay(10);
  65. }   


  66. void main()
  67. {       
  68.             Uart_Init();
  69.                         ms_delay(500);
  70.                         led=0;
  71.                   ESP8266_Set("AT+CWMODE=2");
  72.                         ms_delay(500);
  73.                         ESP8266_Set("AT+CIOBAUD=9600");
  74.                         ms_delay(500);
  75.                         ESP8266_Set("AT+CWSAP="hello","12345678",1,3");
  76.                         ms_delay(500);
  77.                         ESP8266_Set("AT+CIPMUX=1");
  78.                         ms_delay(500);
  79.       ESP8266_Set("AT+CIPSERVER=1,8000");
  80.                         ms_delay(500);
  81.                         ESP8266_Set("AT+CIPSTO=0");
  82.                         ES=1;
  83.          while(1)
  84.          {       
  85.                 if((Recive_table[0]=='+')&&(Recive_table[1]=='I')&&(Recive_table[2]=='P'))
  86.             {
  87.                 if((Recive_table[3]=='D')&&(Recive_table[6]==','))
  88.                      {   
  89.                            if(Recive_table[9]=='0')
  90.                             {
  91.                                                                                                                          led=0;
  92.                                                                                                                        
  93.                                                                                                                         ESP8266_Sent("OFF");
  94.                             }

  95.                            else if(Recive_table[9]=='1')
  96.                             {                                
  97.                                                                                                                          led=1;
  98.                                                                                                                         ESP8266_Sent("ON");                 
  99.                                                                                                                 }
  100.                      }   
  101.                                          }      
  102.     }         
  103. }

  104. void Uart_Interrupt() interrupt 4         
  105. {   
  106.         static uchar i=0;  
  107.         if(RI==1)  
  108.         {   
  109.                 RI=0;   
  110.                 Receive=SBUF;                                                       
  111.                 Recive_table[i]=Receive;   
  112.                 if((Recive_table[i]=='\n'))
  113.                 {                     
  114.                         i=0;
  115.                 }   
  116.                 else i++;                                                                         
  117.         }   
  118.         else TI=0;   
  119. }  

复制代码

举报

回复
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

打开支付宝扫一扫,最高立得1212元红包
搜索

图文热点

更多

社区学堂

更多

客服中心

QQ:187196467 服务时间:周一至周日 8:30-20:30

关注我们

关于我们
关于我们
友情链接
联系我们
帮助中心
网友中心
购买须知
支付方式
服务支持
资源下载
售后服务
定制流程
关注我们
官方微博
官方空间
官方微信
快速回复 返回顶部 返回列表