ESP8266底层程序
#include "public.h"#include "ESP8266.h"#include "usart.h"#include "delay.h"#include "stdio.h"#include "string.h"/***********************************1:OK2:SEND OK3:CLOSE4:ò»Î»êyêy¾Y5:á½Î»êyêy¾Y6:èyλêyêy¾Y7:·tÎñÆ÷±»á¬½ó8:êÕμ½wifiÃû3ÆoíÃüÂë9:êÕμ½Ãû3ÆoíÃüÂë10:ERROR11;¸′λ12:·μ»Ø>13:í¸′«·μ»Ø14:í¸′«½óêÕíê3é************************************//************************************ ¶¨òåOLED*************************************/u8 Set_Mode="Set Mode\0";u8 Connect_Wifi="Connect Wifi\0";u8 Connect_TCP="Connect TCP\0";u8 Connect_UDP="Connect UDP\0";u8 State="OK\0";u8 Wite="Wite connect\0";u8 Client="Client\0";u8 SSID_PASSWORD="SSID PASSWORD\0";/************************************ APP¿ØÖÆWIFIᬽó*************************************/char CWJAP_APP="AT+CWJAP=";/************************************ Ãüáî·μ»Ø×′ì¬*************************************/int ESP8266_state = 0;
/************************************ Ãüáî·¢Ëíoˉêy*************************************/void SEND_Order(char* order){ int i; for(i=0; i < strlen(order); i++) { USART_SendData(USART1,order); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE) == Bit_RESET); }}/************************************ íË3öí¸′«*************************************/void SEND_EN_EXIT(void){ delay_ms(100); SEND_Order(CIPSEND_EXIT); delay_ms(100);}/************************************ í¸′«·¢Ëíoˉêy*************************************/void SEND_EN_Order(char *data){ SEND_Order(data); ESP8266_state = 0;}/************************************ ·Çí¸′«·¢Ëíoˉêy*************************************/void SEND_DIS_Order(char *data,char *len){ char buff=""; strcat(buff,CIPSEND_Dis); strcat(buff,len); strcat(buff,EXIT); SEND_Order(buff); while(ESP8266_state !=1); ESP8266_state = 0; SEND_Order(data); while(ESP8266_state != 2); ESP8266_state = 0;}/************************************ êy¾Y·¢ËíÄ£ê½éèÖà 0:·Çí¸′«Ä£ê½ 1:í¸′«Ä£ê½*************************************/void Send_Mode(int S_Mode){ switch(S_Mode) { case 0: //·Çí¸′« SEND_Order(CIPMODE_Dis); while(ESP8266_state != 1); ESP8266_state = 0; break; case 1: //í¸′« SEND_Order(CIPMODE_EN); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPSEND_EN); delay_ms(10); break; default: break; }}/************************************ 1춨wifi3õê¼»ˉoˉêy*************************************/void esp8266_config(void) //ESP82663õê¼»ˉ{ SEND_Order(ATE); while(ESP8266_state != 1); ESP8266_state = 0; // OLED_ShowString(0,0,Set_Mode,12); Draw_Font16B(0,10,BLUE,Set_Mode); SEND_Order(mode); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,1,State,12); Draw_Font16B(0,30,BLUE,State); // OLED_ShowString(0,2,Connect_Wifi,12); Draw_Font16B(0,50,BLUE,Connect_Wifi); SEND_Order(CWJAP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,3,State,12); Draw_Font16B(0,70,BLUE,State);
// OLED_ShowString(0,4,Connect_TCP,12); Draw_Font16B(0,90,BLUE,Connect_TCP); SEND_Order(CIPSTART_TCP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,5,State,12); Draw_Font16B(0,110,BLUE,State);}/************************************ APP¿ØÖÆwifiᬽó3õê¼»ˉoˉêy*************************************/void esp8266_config_APP(void){ char symbol = "\"\",\"\"\r\n"; int SSID_PASSWORD_COUNT=10; int data_count=0; SEND_Order(ATE); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(mode_APP); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPAP); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CWSAP); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPMUX_EN); while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(CIPSERVER_EN); //éèÖÃÎaTCP·tÎñÆ÷ while(ESP8266_state!=1); ESP8266_state=0; while(1) {// OLED_ShowString(0,0,Wite,12); if(ESP8266_state==7) { delay_ms(1000); ESP8266_state=0;// OLED_ShowString(0,1,Client,12); } if(ESP8266_state==9) { ESP8266_state=0;// OLED_ShowString(0,2,SSID_PASSWORD,12); break; } } CWJAP_APP=symbol; while(1) { CWJAP_APP = json_data; SSID_PASSWORD_COUNT++; data_count++; if(json_data==',') { CWJAP_APP=symbol; CWJAP_APP=symbol; CWJAP_APP=symbol; data_count++; SSID_PASSWORD_COUNT+=3; } if(data_count == count_flag) { CWJAP_APP = symbol; CWJAP_APP = symbol; CWJAP_APP = symbol; CWJAP_APP = '\0'; break; } } ESP8266_state=0; SSID_PASSWORD_COUNT=10; data_count=0; SEND_Order(CIPSERVER_DIS); //éèÖÃÎa·ÇTCP·tÎñÆ÷ while(ESP8266_state != 1); ESP8266_state = 0; SEND_Order(RST); //¸′λ while(ESP8266_state != 1); ESP8266_state = 0; delay_ms(1000); SEND_Order(CIPMUX_DIS); //éèÖ÷Ƕàᬽó while(ESP8266_state != 1) ESP8266_state = 0; SEND_Order(ATE); while(ESP8266_state != 1); ESP8266_state = 0; ESP8266_state = 0; SEND_Order(mode); while(ESP8266_state != 1); ESP8266_state = 0; // OLED_ShowString(0,3,Connect_Wifi,12); SEND_Order(CWJAP_APP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,4,State,12);
// OLED_ShowString(0,5,Connect_TCP,12); SEND_Order(CIPSTART_TCP); while(ESP8266_state != 1); ESP8266_state = 0;// OLED_ShowString(0,6,State,12);}
页:
[1]