|
正在学习ESP8266或者已经会了的坛友们,想请问如下代码有没有问题呢?
单片机和ESP8266连接正常,但是执行代码后,用手机或者电脑网络调试助手给ESP发1,LED只是闪烁一下,而且收不到ESP发送的打开和关闭,这是为什么呢?- #include<reg52.h>#include<intrins.h> #define uchar unsigned char#define uint unsigned int sbit led=P1^0;uchar Receive,i; uint n;uchar Recive_table[15]; void ms_delay(uint t){ uint i,j; for(i=t;i>0;i--) for(j=110;j>0;j--);}void us_delay(uchar t){ while(t--);}void Uart_Init(){ SCON=0x50; PCON=0x00; TMOD=0x21; TH1=0xfd; TL1=0xfd; EA=1; ES=1; TR1=1; }void Send_Uart(uchar value){ ES=0; TI=0; SBUF=value; while(TI==0); TI=0; ES=1; }void ESP8266_Set(uchar *puf) { while(*puf!='\0') { Send_Uart(*puf); us_delay(5); puf++; } us_delay(5); Send_Uart('\r'); us_delay(5); Send_Uart('\n'); } void ESP8266_Sent(uchar *puf) { ESP8266_Set("AT+CIPSEND=0,2"); while(*puf!='\0') { Send_Uart(*puf); us_delay(5); puf++; } us_delay(5); Send_Uart('\n'); ms_delay(10);} void main(){ Uart_Init(); ms_delay(500); led=0; ESP8266_Set("AT+CWMODE=2"); ms_delay(500); ESP8266_Set("AT+CIOBAUD=9600"); ms_delay(500); ESP8266_Set("AT+CWSAP="hello","12345678",1,3"); ms_delay(500); ESP8266_Set("AT+CIPMUX=1"); ms_delay(500); ESP8266_Set("AT+CIPSERVER=1,8000"); ms_delay(500); ESP8266_Set("AT+CIPSTO=0"); ES=1; while(1) { if((Recive_table[0]=='+')&&(Recive_table[1]=='I')&&(Recive_table[2]=='P')) { if((Recive_table[3]=='D')&&(Recive_table[6]==',')) { if(Recive_table[9]=='0') { led=0; ESP8266_Sent("OFF"); } else if(Recive_table[9]=='1') { led=1; ESP8266_Sent("ON"); } } } } }void Uart_Interrupt() interrupt 4 { static uchar i=0; if(RI==1) { RI=0; Receive=SBUF; Recive_table[i]=Receive; if((Recive_table[i]=='\n')) { i=0; } else i++; } else TI=0; }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|