标题:
单片机控制ESP8266的代码问题
[打印本页]
作者:
1061897836
时间:
2018-11-16 21:02
标题:
单片机控制ESP8266的代码问题
正在学ESP8266或者已经会了的坛友们,想请问这个代码有问题吗?
模块和单片机连接没有什么问题,但是执行代码后,给ESP发送1,LED只会闪烁一下,添加了延时也这样,而且也收不到ESP发送的打开和关闭,是什么原因呢?
作者:
1061897836
时间:
2018-11-16 21:13
发错了代码,这个才是
#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;
}
复制代码
作者:
小猫猫爱吃鱼
时间:
2018-11-16 22:15
你的代码能编译通过?
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1