本人整合了各种例程,整理出一份较为完整的教程
单片机源程序如下:
- #include <reg52.h>
- #include "lcd1602.h"
- #include "esp8266.h"
- //连接到Wi-Fi后,亮第一个灯
- void EventHandler_WifiConnected(){
- P1 &= 0xFE;
- }
- //获得IP后,亮第二个灯
- void EventHandler_IpGot(){
- P1 &= 0xFD;
- ESP01_ConnectToTCPServer();
- }
- //连接到TCP服务器后,亮第三个灯
- void EventHandler_TcpServerConnected(){
- P1 &= 0xFB;
- }
- //将ESP8266送来的信息,送去LCD显示。
- void EventHandler_MsgReceived(unsigned char* head){
- LCD_writeLine(head);
- }
- //初始化
- void init(){
- ESP01_Event_WifiConnected = &EventHandler_WifiConnected; //事件注册
- ESP01_Event_IpGot = &EventHandler_IpGot; //事件注册
- ESP01_Event_TcpServerConnected = &EventHandler_TcpServerConnected; //事件注册
- ESP01_Event_MsgReceived = &EventHandler_MsgReceived; //事件注册
- ESP01_Init();
- LCD_init();
- }
- void main(){
- init();
- while(1);
- }
复制代码
所有资料51hei提供下载:
wifi.zip
(46.52 KB, 下载次数: 33)
|