#include "stc8.h"
#include "def.h"
#include "delay.h"
#include "z24c02.h"
#include "uart.h"
#include "string.h"
sbit led=P5^5;
extern u8 xdata RX_buffer[tbuf];
extern u8 RX_num;
u8 code esp_at[]="AT\r\n";
u8 code esp_cwmode[]="AT+CWMODE=3\r\n";
u8 code esp_cifsr[]="AT+CIFSR\r\n";
u8 code esp_cipsend[]="AT+CIPSEND=6\r\n";
u8 code esp_test[]="sunny\r\n";
u8 code esp_cipserver[]="AT+CIPSERVER=1,5000\r\n";
u8 code esp_cipmux[]="AT+CIPMUX=1\r\n";
u8 code esp_rst[]="AT+RST\r\n";
u8 Data_compare(u8 *p)
{
if(strstr(RX_buffer,p)!=NULL)
return 1;
else
return 0;
}
void main()
{
u8 num=3;
UartInit();
ES = 1;
IE2 = 0x01;
EA = 1;
delay1ms(800);
Uart1SendStr(" esp8622 wifi模块 服务器(sever)模式测试\r\n");
memset(RX_buffer, 0, tbuf);
RX_num=0;
while(1)
{
Uart2SendStr(esp_at);
if(Data_compare("OK"))break;
else Uart1SendStr("ERROR1,some problems with ESP8266 \r\n");
delay1ms(600);
}
Uart1SendStr("OK,mcu connection success with ESP8266! \r\n");
memset(RX_buffer, 0, tbuf);
RX_num=0;
while(1)
{
Uart2SendStr(esp_cwmode);
if(Data_compare("OK")||Data_compare("no change"))break;
else Uart1SendStr("ERROR2,some problems with ESP8266 \r\n");
delay1ms(600);
}
Uart1SendStr("OK,set mode as AP+Station with ESP8266! \r\n");
memset(RX_buffer, 0, tbuf);
RX_num=0;
while(1)
{
Uart2SendStr(esp_cipmux);
if(Data_compare("OK"))break;
else Uart1SendStr("ERROR3,some problems with ESP8266 \r\n");
delay1ms(600);
}
memset(RX_buffer, 0, tbuf);
RX_num=0;
while(1)
{
Uart2SendStr(esp_cipserver);
if(Data_compare("OK"))break;
else Uart1SendStr("ERROR4,some problems with ESP8266 \r\n");
delay1ms(600);
}
memset(RX_buffer, 0, tbuf);
RX_num=0;
while(1)
{
Uart2SendStr(esp_cifsr);
if(Data_compare("OK"))break;
else Uart1SendStr("ERROR5,some problems with ESP8266 \r\n");
delay1ms(600);
}
Uart1SendStr(RX_buffer);
memset(RX_buffer, 0, tbuf);
RX_num=0;
while(1)
{
if(Data_compare("LEDK"))
{
ES = 0;
IE2 = 0x00;
led = 0;
memset(RX_buffer, 0, tbuf);
RX_num=0;
Uart1SendStr("led is open!\r\n");
ES = 1;
IE2 = 0x01;
}
else if(Data_compare("LEDG"))
{
ES = 0;
IE2 = 0x00;
led = 1;
memset(RX_buffer, 0, tbuf);
RX_num=0;
Uart1SendStr("led is close!\r\n");
ES = 1;
IE2 = 0x01;
}
}
}
|