智能车制作
标题:
51MCU发送指令给wifi模块esp8266(求助)
[打印本页]
作者:
追步者
时间:
2017-12-1 11:03
标题:
51MCU发送指令给wifi模块esp8266(求助)
51MCU发送指令给wifi模块esp8266
以下是代码:
#include<reg51.h>
#include<intrins.h>
//#include"lcd.h"
#define led P1
sbit beep=P2^5;
unsigned char esp_at[11] = "AT+RST\r \n"; //""算一个字符
unsigned char esp_cwmode[16] = "AT+CWMODE=2\r \n";
unsigned char esp_cipmux[16] = "AT+CIPMUX=1\r \n";
unsigned char esp_server[24] = "AT+CIPSERVER=1,8080\r \n";
//unsigned char PuZh[]=" Pechin Science ";
//unsigned char esp_at[11] = "AT+RST\r\n";
//unsigned char esp_at[11] = "AT+RST\r\n";
//--声明全局函数--//
void UsartConfiguration();
void sendString(unsigned char *s);
void sendByte(unsigned char b);
void espInit();
//void remote_control(unsigned char ldat);
/*
void delay(unsigned int i)
{
while(i--);
}
*/
void main()
{
//unsigned char i;
led=0x00;
UsartConfiguration();
espInit();
//LcdInit();
while(1)
{
//remote_control(unsigned char ldat);
led=0xff;
}
}
void UsartConfiguration()
{
SCON=0X50; //设置为工作方式1
TMOD=0X20; //设置计数器工作方式2
PCON=0X80; //波特率加倍
TH1=0XF3; //计数器初始值设置,注意波特率是4800的
TL1=0XF3;
//ES=1; //打开接收中断
EA=1; //打开总中断
TR1=1; //打开计数器
}
void espInit()
{
unsigned int a;
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
sendString(esp_at);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
sendString(esp_cwmode);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
sendString(esp_cipmux);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
sendString(esp_server);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
for (a=0; a<50000; a++);
EA=0;
ES=1;
}
void sendByte(unsigned char b)
{
SBUF = b;
while(!TI);
TI=0;
}
//发送字符串
void sendString(unsigned char *s)
{
while(*s != '\0') //字符串默认结尾'\0',以此来判断字符串的结束
{
sendByte(*s);
s++;
}
}
通过使用串口工具,检测到51mcu可以发送指令,可是接上8266以后,8266一直没有响应,使用网络助手,也没有办法连接上8266.求助。
作者:
metoyou_dul6O
时间:
2018-2-11 14:31
波特率的问题吧,esp8266默认的是115200吧
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2