通过51单片机、Arduino等实现AT指令配置8266模块,主要是通过串口通信实现的,博主学校的时候用的是51单片机给8266配置,arduino等原理相同,但是通过这种方法配置8266不是很稳定,会出现莫名重启等错误,也有可能是我外围电路没有去设计的原因。
本次主要涉及到的AT指令如下
//ATE0 关闭回显
uchar code closeBack[6]={0x41,0x54,0x45,0x30,0x0D,0x0A};
//AT+UART=9600,0,0,0 设置UART串口模式
uchar code setUART[20]={0x41,0x54,0x2B,0x55,0x41,0x52,0x54,0x3D,0x39,0x36,0x30,0x30,0x2C,0x30,0x2C,0x30,0x2C,0x30,0x0D,0x0A};
//AT+CWMODE=1 设置成Station模式
uchar code setStationMode[13]={0x41,0x54,0x2B,0x43,0x57,0x4D,0x4F,0x44,0x45,0x3D,0x31,0x0D,0x0A};
//AT+CWJAP="ccc","455455455" 连接WIFI
uchar code linkWifi[28]={0x41,0x54,0x2B,0x43,0x57,0x4A,0x41,0x50,0x3D,0x22,0x63,0x63,0x63,0x22,0x2C,0x22,0x34,0x35,0x35,0x34,0x35,0x35,0x34,0x35,0x35,0x22,0x0D,0x0A};
//AT+CIPMUX=0 设置单路连接模式
uchar code setSingleLinkMode[13]={0x41,0x54,0x2B,0x43,0x49,0x50,0x4D,0x55,0x58,0x3D,0x30,0x0D,0x0A};
//AT+RST 重启
uchar code RST[8]={0x41,0x54,0x2B,0x52,0x53,0x54,0x0D,0x0A};
//AT+CIPSTART="TCP","192.168.199.134",8080 连接TCP服务器
uchar code linkTCPServe[42]={0x41,0x54,0x2B,0x43,0x49,0x50,0x53,0x54,0x41,0x52,0x54,0x3D,0x22,0x54,0x43,0x50,0x22,0x2C,0x22,0x31,0x39,0x32,0x2E,0x31,0x36,0x38,0x2E,0x31,0x39,0x39,0x2E,0x31,0x33,0x34,0x22,0x2C,0x38,0x30,0x38,0x30,0x0D,0x0A};
//AT+CIPSEND= 发送数据
uchar code sendDate[11]={0x41,0x54,0x2B,0x43,0x49,0x50,0x53,0x45,0x4E,0x44,0x3D};
当然你也可以使用如下方式表示变量
//ATE0 关闭回显
uchar code closeBack[]="ATE0\r\n";
//AT+UART=9600,0,0,0 设置UART串口模式
uchar code setUART[]="AT+UART=9600,0,0,0\r\n";
//AT+CWMODE=1 设置成Station模式
uchar code setStationMode[]="AT+CWMODE=1\r\n";
//AT+CWJAP="ccc","455455455" 连接WIFI
uchar code linkWifi[]="AT+CWJAP=\"ccc\",\"455455455\"\r\n";
//AT+CIPMUX=0 设置单路连接模式
uchar code setSingleLinkMode[]="AT+CIPMUX=0";
//AT+RST 重启
uchar code RST[]="AT+RST";
//AT+CIPSTART="TCP","192.168.199.134",8080 连接TCP服务器
uchar code linkTCPServe[]="AT+CIPSTART=\"TCP\",\"192.168.199.134\",8080";
//AT+CIPSEND= 发送数据
uchar code sendDate[]="AT+CIPSEND=";
以上第一种方法要写个循环一个一个发,而第二种比较方便,可以直接使用printf()函数发送。
所用主要是模块作为station连接tcp服务器的一个过程,下面附上我学习时候写的代码,可能有比较多附加的东西,方便我当时调试执行到哪部了。
#include
#include
#define uchar unsigned char
#define uint unsigned int
/******************本地变量声明******************/
uchar Buffer; //接收串口数据
/******************端口引脚定义******************/
sbit K1=P3^4; //正转按键
sbit K2=P3^5; //反转按键
sbit K3=P3^6; //停止按键
sbit LED1=P1^0; //正转灯
sbit LED2=P1^1; //反转灯
sbit LED3=P1^2; //停止灯
sbit LED4=P1^3; //连接服务器成功
sbit sig=P2^1;
sbit led=P2^0;
/******************电机相序表定义******************/
uchar code CW[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; //电机正时钟旋转相序表
uchar code CCW[8]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01}; //电机逆时钟旋转相序表
/**********************ESP8266指令定义***********************
//ATE0 关闭回显
uchar code closeBack[6]={0x41,0x54,0x45,0x30,0x0D,0x0A};
//AT+UART=9600,0,0,0 设置UART串口模式
uchar code setUART[20]={0x41,0x54,0x2B,0x55,0x41,0x52,0x54,0x3D,0x39,0x36,0x30,0x30,0x2C,0x30,0x2C,0x30,0x2C,0x30,0x0D,0x0A};
//AT+CWMODE=1 设置成Station模式
uchar code setStationMode[13]={0x41,0x54,0x2B,0x43,0x57,0x4D,0x4F,0x44,0x45,0x3D,0x31,0x0D,0x0A};
//AT+CWJAP="ccc","455455455" 连接WIFI
uchar code linkWifi[28]={0x41,0x54,0x2B,0x43,0x57,0x4A,0x41,0x50,0x3D,0x22,0x63,0x63,0x63,0x22,0x2C,0x22,0x34,0x35,0x35,0x34,0x35,0x35,0x34,0x35,0x35,0x22,0x0D,0x0A};
//AT+CIPMUX=0 设置单路连接模式
uchar code setSingleLinkMode[13]={0x41,0x54,0x2B,0x43,0x49,0x50,0x4D,0x55,0x58,0x3D,0x30,0x0D,0x0A};
//AT+RST 重启
uchar code RST[8]={0x41,0x54,0x2B,0x52,0x53,0x54,0x0D,0x0A};
//AT+CIPSTART="TCP","192.168.199.134",8080 连接TCP服务器
uchar code linkTCPServe[42]={0x41,0x54,0x2B,0x43,0x49,0x50,0x53,0x54,0x41,0x52,0x54,0x3D,0x22,0x54,0x43,0x50,0x22,0x2C,0x22,0x31,0x39,0x32,0x2E,0x31,0x36,0x38,0x2E,0x31,0x39,0x39,0x2E,0x31,0x33,0x34,0x22,0x2C,0x38,0x30,0x38,0x30,0x0D,0x0A};
//AT+CIPSEND= 发送数据
uchar code sendDate[11]={0x41,0x54,0x2B,0x43,0x49,0x50,0x53,0x45,0x4E,0x44,0x3D};
********************ESP8266指令定义结束*********************/
/**********************ESP8266 AT指令定义***********************
//ATE0 关闭回显
uchar code closeBack[]="ATE0\r\n";
//AT+UART=9600,0,0,0 设置UART串口模式
uchar code setUART[]="AT+UART=9600,0,0,0\r\n";
//AT+CWMODE=1 设置成Station模式
uchar code setStationMode[]="AT+CWMODE=1\r\n";
//AT+CWJAP="ccc","455455455" 连接WIFI
uchar code linkWifi[]="AT+CWJAP=\"ccc\",\"455455455\"\r\n";
//AT+CIPMUX=0 设置单路连接模式
uchar code setSingleLinkMode[]="AT+CIPMUX=0";
//AT+RST 重启
uchar code RST[]="AT+RST";
//AT+CIPSTART="TCP","192.168.199.134",8080 连接TCP服务器
uchar code linkTCPServe[]="AT+CIPSTART=\"TCP\",\"192.168.199.134\",8080";
//AT+CIPSEND= 发送数据
uchar code sendDate[]="AT+CIPSEND=";
/********************ESP8266 AT指令定义结束*********************/
/******************延时函数******************/
void delay(uint x)
{
uint i,j;
for(i=0;i