20170225(应需要,继续使用此模块!!!)
说一下如何通过内网和外网来控制我的ESP8266的数据模块
1、内网控制:(要求手机直接连接在ESP8266的WIFI上面,使用“TCP连接”这款软件来控制ESP8266的数据,模块的设置按照之前上面的主机端的设置模式即可)
这种情况下需要设置ESP8266模块为AP模式,也就是AT+CWMODE=2(AP Mode as a TCP Server),这个时候手机作为Client端,通过无线连接到AP端。如下图所示:
2、经过家庭WIFI无线路由器节点来让外网访问ESP8266模块,需要知道的是ESP8266的IP地址和MAC地址及其端口。
或者直接下载云盘文档链接:http://pan.baidu.com/s/1c2lAePE 密码:8zgm
上面的这篇文档,没有涉及到DMZ服务的配置,现在的路由器需要设置好DMZ服务器之后才能将本地的ESP8266模块的数据发送出去!
还可以参考这篇博客园的博客:http://www.cnblogs.com/yangfengwu/p/5295632.html
一、ESP8266的设置:AT+RST --> AT+CWMODE=3 --> AT+CWLAP --> AT+CWJAP="ssid of Router","PassWords of Router" --> AT+CIFSR --> AT+CIPMUX=1 -->AT+CIPSERVER=1,333
复位ESP 配置为AP/Station兼容模式 列出所有AP 找到当前的无线wifi路由器,输入账户密码,加入AP 列出ESP8266的IP和MAC地址 设置为多连模式 设置服务端口
二、TP link路由器设置:
首先登陆家里的路由器界面,管理员密码
在应用管理中获得ESP8266的密码和MAC地址,同时绑定IP和MAC地址,保证每次启动的时候IP不用动态分配,保持IP不变!
在应用管理中设置启用DMZ主机服务,将ESP8266模块暴露在公网中,在DMZ主机IP地址填写之前路由器分配的IP地址即可!
在路由设置中获得路由器的外网IP地址:121.xx.xxx.xx
通过EasyTCP软件来链接我的ESP8266模块:(如下图所示)
手机TCP端数据发送 ESP8266客户端数据监控
不设置路由器来实现ESP8266的控制(采用内网透传的方式实现此功能)Time:2017 02 26
本来想使用免费的内网透传软件Xtunnel软件来做实验的,我用 Sockettool软件死活是连接不上我的Xtunnel公网,没办法就注册了花生壳,交了钱拿个域名(6元)和1G的流量(10元)
注册好花生壳的域名和流量之后,我们开始建立内网透传的IP和端口:
下面我们开始设置ESP8266,这个设置和上面的一样,只不过我们不需要设置路由器的DMZ功能将内网主机ESP8266的IP地址和端口映射到广域网上啦~
AT
AT+RST
AT+CWLAP
AT+CWJAP="xxxx","xxxx"
AT+CIFSR
AT+CIPMUX=1
AT+CIPSERVER=1,333
设置完之后就能传输数据啦!!非常方便
基于单片机控制的ESP8266模块的实验如下:
主机端:(步骤如下)
AT固件按照之前提供的AT固件包和烧录位置来烧录即可,在失忆之前先使用串口来直接调试ESP8266是否已经烧录完成!
单片机型号是STM32C8T6,串口使用的是UART2,代码如下:
main.c文件内容
1 #include "stm32f10x.h" 2 #include "app.h" 3 #include "LED.h" 4 #include "delay.h" 5 #include "oled.h" 6 7 #define T 1000 9 unsigned char Return[200]={' '}; 10 unsigned char Clear[200]={' '}; 11 unsigned char Count=0; 12 13 void delayms(void) 14 { 15 int i=0,j=0; 16 for(i=0;i<1000;i++) 17 { 18 for(j=0;j<1000;j++) ; 19 } 20 } 26 int main(void) 27 { 28 unsigned char Str[]="ESP8266 & STM32C8T6!"; 29 unsigned char i=0; 30 char Len = 0; 44 45 //Server ESP8266 46 char Server_Step1[]="AT\r\n"; 47 char Server_Step2[]="AT+RST\r\n"; 48 char Server_Step3[]="AT+CWMODE=2\r\n"; 49 char Server_Step4[]="AT+CWSAP=\"UESTC-MM\",\"1234abcd\",1,3\r\n"; 50 char Server_Step5[]="AT+CIFSR\r\n"; 51 char Server_Step6[]="AT+CIPMODE=0\r\n"; 52 char Server_Step7[]="AT+CIPMUX=1\r\n"; 53 char Server_Step8[]="AT+CIPSERVER=1,333\r\n"; 55 unsigned char Info1[]={"SSID:UESTC-MM"}; 56 unsigned char Info2[]={"PSWD:1234abcd"}; 57 58 All_Init(); 59 LED_init(); 60 init_OLED(); 61 USART2_Puts(Str); 62 OLED_P6x8Str(1,1,Str); 63 64 65 OLED_P6x8Str(1,2,Info1); 66 OLED_P6x8Str(1,3,Info2); 67 //Command 1 68 USART2_Puts(Server_Step1); delayms(); delay_ms(T); delay_ms(T); 69 Return[Count] = '\0'; OLED_Fill(0); 70 OLED_P6x8Str(1,1,Return); Count = 0; 71 for(i=0;i<200;i++) 72 { 73 Return[i] = ' '; 74 } 75 //Command 2 76 USART2_Puts(Server_Step2); delayms(); delay_ms(T); delay_ms(T); 77 Return[Count] = '\0'; OLED_Fill(0); 78 OLED_P6x8Str(1,1,Return); Count = 0; 79 for(i=0;i<200;i++) 80 { 81 Return[i] = ' '; 82 } 83 //Command 3 84 USART2_Puts(Server_Step3); delayms(); delay_ms(T); delay_ms(T); 85 Return[Count] = '\0'; OLED_Fill(0); 86 OLED_P6x8Str(1,1,Return); Count = 0; 87 for(i=0;i<200;i++) 88 { 89 Return[i] = ' '; 90 } 91 //Command 4 92 USART2_Puts(Server_Step4); delayms(); delay_ms(T); delay_ms(T); 93 Return[Count] = '\0'; //OLED_Fill(0); 94 OLED_P6x8Str(1,1,Return); Count = 0; 95 for(i=0;i<200;i++) 96 { 97 Return[i] = ' '; 98 } 99 //Command 5 100 USART2_Puts(Server_Step5); delayms(); delay_ms(T); delay_ms(T); 101 Return[Count] = '\0'; OLED_Fill(0); 102 OLED_P6x8Str(1,1,Return); Count = 0; 103 for(i=0;i<200;i++) 104 { 105 Return[i] = ' '; 106 } 107 //Command 6 108 USART2_Puts(Server_Step6); delayms(); delay_ms(T); delay_ms(T); 109 Return[Count] = '\0'; OLED_Fill(0); 110 OLED_P6x8Str(1,1,Return); Count = 0; 111 for(i=0;i<200;i++) 112 { 113 Return[i] = ' '; 114 } 115 //Command 7 116 USART2_Puts(Server_Step7); delayms(); delay_ms(T); delay_ms(T); 117 Return[Count] = '\0'; OLED_Fill(0); 118 OLED_P6x8Str(1,1,Return); Count = 0; 119 for(i=0;i<200;i++) 120 { 121 Return[i] = ' '; 122 } 123 //Command 8 124 USART2_Puts(Server_Step8); delayms(); delay_ms(T); delay_ms(T); 125 Return[Count] = '\0'; OLED_Fill(0); 126 OLED_P6x8Str(1,1,Return); Count = 0; 127 for(i=0;i<200;i++) 128 { 129 Return[i] = ' '; 130 } 132 while(1) 133 { 134 OLED_P6x8Str(1,1,Return); 135 delay_ms(100); 136 switch(Return[11]){ 137 case '0': break; 138 case '1': OLED_Fill(0); break; 139 case '2': LED_H(); break; 140 case '3': LED_L(); break; 141 default:break; 142 } 143 Count = 0 ; 144 } 145 }
LED.c
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #include "LED.h" 2 3 void LED_init(void) 4 { 5 GPIO_InitTypeDef GPIO_InitStructure; 6 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); 7 8 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; 9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 11 GPIO_Init(GPIOB, &GPIO_InitStructure); 12 13 GPIO_ResetBits(GPIOB,GPIO_Pin_5); 14 } 15 void LED_H(void) 16 { 17 GPIO_ResetBits(GPIOB,GPIO_Pin_5); 18 } 19 void LED_L(void) 20 { 21 GPIO_SetBits(GPIOB,GPIO_Pin_5); 22 }
LED.h
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #ifndef _LED_H_ 2 #define _LED_H_ 3 #include "stm32f10x.h" 4 5 void LED_init(void); 6 void LED_H(void); 7 void LED_L(void); 8 9 #endif
USART.c
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #include "stm32f10x.h" 2 #include <stdio.h> //ÏÂÃæstrlenº¯ÊýÐèÒª´ËÍ·Îļþ 3 #include "USART.h" 4 5 /********************************************************** 6 ** º¯ÊýÃû:u32tostr 7 ** ¹¦ÄÜÃèÊö: ½«Ò»¸ö32λµÄ±äÁ¿datתΪ×Ö·û´®£¬±ÈÈç°Ñ1234תΪ"1234" 8 ** ÊäÈë²ÎÊý: dat:´øתµÄlongÐ͵ıäÁ¿ 9 str:Ö¸Ïò×Ö·ûÊý×éµÄÖ¸Õ룬ת»»ºóµÄ×Ö½Ú´®·ÅÔÚÆäÖÐ 10 ** Êä³ö²ÎÊý: ÎÞ 11 ***********************************************************/ 12 void u32tostr(unsigned long dat,char *str) 13 { 14 char temp[20]; 15 unsigned char i=0,j=0; 16 i=0; 17 while(dat) 18 { 19 temp[i]=dat%10+0x30; 20 i++; 21 dat/=10; 22 } 23 j=i; 24 for(i=0;i<j;i++) 25 { 26 str[i]=temp[j-i-1]; 27 } 28 if(!i) {str[i++]='0';} 29 str[i]=0; 30 } 31 32 /********************************************************** 33 ** º¯ÊýÃû: strtou32 34 ** ¹¦ÄÜÃèÊö: ½«Ò»¸ö×Ö·û´®×ªÎª32λµÄ±äÁ¿£¬±ÈÈç"1234"תΪ1234 35 ** ÊäÈë²ÎÊý: str:Ö¸Ïò´ýת»»µÄ×Ö·û´® 36 ** Êä³ö²ÎÊý: ÎÞ 37 ** ·µ»Ø£º×ª»»ºóµÄÊýÖµ 38 ***********************************************************/ 39 unsigned long strtou32(char *str) 40 { 41 unsigned long temp=0; 42 unsigned long fact=1; 43 unsigned char len=strlen(str); 44 unsigned char i; 45 for(i=len;i>0;i--) 46 { 47 temp+=((str[i-1]-0x30)*fact); 48 fact*=10; 49 } 50 return temp; 51 } 52 53 void NVIC_Configuration(void) 54 { 55 NVIC_InitTypeDef NVIC_InitStructure; 56 /* Configure the NVIC Preemption Priority Bits */ 57 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); 58 59 /* Enable the USARTy Interrupt */ 60 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; 61 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; 62 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 63 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 64 NVIC_Init(&NVIC_InitStructure); 65 66 } 67 68 /********************************************************** 69 ** º¯ÊýÃû: Usart_Configuration 70 ** ¹¦ÄÜÃèÊö: ´®¿Ú1ÅäÖÃ, °üÀ¨´®¿ÚʱÖÓ£¬GPIOÅäÖà 71 ** ÊäÈë²ÎÊý: ÎÞ 72 ** Êä³ö²ÎÊý: ÎÞ 73 ***********************************************************/ 74 void Usart_Configuration(void) 75 { 76 GPIO_InitTypeDef GPIO_InitStructure; //GPIO¿âº¯Êý½á¹¹Ìå 77 USART_InitTypeDef USART_InitStructure;//USART¿âº¯Êý½á¹¹Ìå 78 USART_ClockInitTypeDef USART_ClockInitStructure; 79 //ʹÄÜ´®¿Ú1£¬GPIOA£¬AFIO×ÜÏß 80 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE); 81 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); 82 /* Configure USART1 Tx (PA9) as alternate function push-pull */ 83 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //Pin_9 84 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//PA9ʱÖÓËÙ¶È50MHz 85 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÊä³ö 86 GPIO_Init(GPIOA, &GPIO_InitStructure); 87 /* Configure USART1 Rx (PA10) as input floating */ 88 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//Pin_10 89 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉÏÀÊäÈë 90 GPIO_Init(GPIOA, &GPIO_InitStructure); 91 92 USART_InitStructure.USART_BaudRate =115200; //²¨ÌØÂÊ9600 93 USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8λÊý¾Ý 94 USART_InitStructure.USART_StopBits = USART_StopBits_1; //1¸öֹͣλ 95 USART_InitStructure.USART_Parity = USART_Parity_No; //ÆæżʧÄÜ 96 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Ó²¼þÁ÷¿ØÖÆʧÄÜ 97 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //·¢ËÍ¡¢½ÓÊÕʹÄÜ 98 99 USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; 100 USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;//¿ÕÏÐʱÖÓΪµÍµçƽ 101 USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;//ʱÖÓµÚ¶þ¸ö±ßÑؽøÐÐÊý¾Ý²¶»ñ 102 USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;//×îºóһλÊý¾ÝµÄʱÖÓÂö³å²»´ÓSCLKÊä³ö 103 104 USART_ClockInit(USART2, &USART_ClockInitStructure); 105 USART_Init(USART2, &USART_InitStructure); //³õʼ»¯½á¹¹Ìå 106 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //ʹÄÜUSART2µÄÖжϹ¦ÄÜ 107 USART_Cmd(USART2, ENABLE); //ʹÄÜ´®¿Ú1 108 109 NVIC_Configuration(); 110 } 111 112 //¼ÓÈëÒÔÏ´úÂë,Ö§³Öprintfº¯Êý,¶ø²»ÐèҪѡÔñuse MicroLIB 113 /***************************START*********************/ 114 /* 115 #if 1 116 #pragma import(__use_no_semihosting) 117 //±ê×¼¿âÐèÒªµÄÖ§³Öº¯Êý 118 struct __FILE 119 { 120 int handle; 121 /* Whatever you require here. If the only file you are using is */ 122 /* standard output using printf() for debugging, no file handling */ 123 /* is required. */ 124 //}; 125 /* FILE is typedef¡¯ d in stdio.h. */ 126 //FILE __stdout; 127 //¶¨Òå_sys_exit()ÒÔ±ÜÃâʹÓðëÖ÷»úģʽ 128 //_sys_exit(int x) 129 //{ 130 // x = x; 131 //} */ 132 //Öض¨Òåfputcº¯Êý 133 int fputc(int ch, FILE *f) 134 { 135 USART2->DR = (u8) ch; 136 while((USART2->SR&0X40)==0);//Ñ»··¢ËÍ,Ö±µ½·¢ËÍÍê±Ï 137 return ch; 138 } 139 //#endif 140 /***************************END*********************/ 141 142 /********************************************************** 143 ** º¯ÊýÃû:USART1_Putc 144 ** ¹¦ÄÜÃèÊö: ´®¿Ú1·¢ËÍÒ»×Ö·û 145 ** ÊäÈë²ÎÊý: c 146 ** Êä³ö²ÎÊý: ÎÞ 147 ***********************************************************/ 148 void USART2_Putc(unsigned char c) 149 { 150 USART2->DR = (u8)c; //Òª·¢Ë͵Ä×Ö·û¸³¸ø´®¿ÚÊý¾Ý¼Ä´æÆ÷ 151 while((USART2->SR&0X40)==0); //µÈ´ý·¢ËÍÍê³É 152 } 153 /********************************************************** 154 ** º¯ÊýÃû:USART1_Puts 155 ** ¹¦ÄÜÃèÊö: ´®¿Ú1·¢ËÍÒ»×Ö·û´® 156 ** ÊäÈë²ÎÊý: Ö¸Õëstr 157 ** Êä³ö²ÎÊý: ÎÞ 158 ***********************************************************/ 159 void USART2_Puts(char * str) 160 { 161 while(*str) 162 { 163 USART2->DR= *str++; 164 while((USART2->SR&0X40)==0);//µÈ´ý·¢ËÍÍê³É 165 } 166 } 167 /********************************************************** 168 ** º¯ÊýÃû:UART_Send_Enter 169 ** ¹¦ÄÜÃèÊö: ´®¿Ú1·¢ËÍÒ»»»Ðзû 170 ** ÊäÈë²ÎÊý: ÎÞ 171 ** Êä³ö²ÎÊý: ÎÞ 172 ***********************************************************/ 173 void UART_Send_Enter(void) 174 { 175 USART2_Putc(0x0d); 176 USART2_Putc(0x0a); 177 } 178 /********************************************************** 179 ** º¯ÊýÃû:UART_Send_Str 180 ** ¹¦ÄÜÃèÊö: ´®¿Ú1·¢ËÍÒ»×Ö·û´®£¬´ø»Ø³µ»»Ðй¦ÄÜ 181 ** ÊäÈë²ÎÊý: Ö¸Õës 182 ** Êä³ö²ÎÊý: ÎÞ 183 ***********************************************************/ 184 void UART_Send_Str(char *s) 185 { 186 187 for(;*s;s++) 188 { 189 if(*s=='\n') 190 UART_Send_Enter(); 191 else 192 USART2_Putc(*s); 193 } 194 } 195 /********************************************************** 196 ** º¯ÊýÃû: UART_Put_Num 197 ** ¹¦ÄÜÃèÊö: STM32FµÄUSART·¢ËÍÊýÖµ 198 ** ÊäÈë²ÎÊý: dat:Òª·¢Ë͵ÄÊýÖµ 199 ** Êä³ö²ÎÊý: ÎÞ 200 ** ˵Ã÷£ºº¯ÊýÖлὫÊýֵתΪÏàÓ¦µÄ×Ö·û´®£¬·¢ËͳöÈ¥¡£±ÈÈç 4567 תΪ "4567" 201 ***********************************************************/ 202 void UART_Put_Num(unsigned long dat) 203 { 204 char temp[20]; 205 u32tostr(dat,temp); 206 UART_Send_Str(temp); 207 } 208 /********************************************************** 209 ** º¯ÊýÃû: UART_Put_Inf 210 ** ¹¦ÄÜÃèÊö: STM32FµÄUSART·¢Ë͵÷ÊÔÐÅÏ¢ 211 ** ÊäÈë²ÎÊý: inf:Ö¸ÏòÌáʾÐÅÏ¢×Ö·û´®µÄÖ¸Õë 212 dat:Ò»¸öÊýÖµ£¬Ç°ÃæµÄÌáʾÐÅÏ¢¾ÍÊÇÔÚ˵Ã÷Õâ¸öÊýÖµµÄÒâÒå 213 ** Êä³ö²ÎÊý: ÎÞ 214 ***********************************************************/ 215 void UART_Put_Inf(char *inf,unsigned long dat) 216 { 217 UART_Send_Str(inf); 218 UART_Put_Num(dat); 219 UART_Send_Str("\n"); 220 }
主机USART.h
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #ifndef __USART__H 2 #define __USART__H 3 #include "stm32f10x.h" 4 #include <string.h> 5 6 void Usart_Configuration(void); 7 void UART_Send_Byte(char c); 8 void UART_Send_Enter(void); 9 10 void UART_Send_Str(char *s); 11 12 void UART_Put_Num(unsigned long dat); 13 void UART_Put_Inf(char *inf,unsigned long dat); 14 15 void u32tostr(unsigned long dat,char *str); 16 unsigned long strtou32(char *str) ; 17 void USART2_Puts( char * str); 18 void USART2_Putc(unsigned char c); 19 #endif
OLED.c
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #include "stm32f10x.h"/*OLEDÏÔʾģ¿é²ÉÓõÄÊÇ4ÏßSPIͨѶ·½Ê½*/ 2 #include "oled.h" 3 #include "delay.h" 4 #define DC_1 GPIO_SetBits(GPIOB, GPIO_Pin_1)//P2^1,Êý¾ÝÃüÁîÑ¡Ôñ¶Ë½ÓÔÚDCÒý½ÅÉÏ 5 #define DC_0 GPIO_ResetBits(GPIOB, GPIO_Pin_1) 6 #define SCLK_1 GPIO_SetBits(GPIOB, GPIO_Pin_12)//P2^2,ʱÖÓÏß½ÓÔÚDOÒý½ÅÉÏ 7 #define SCLK_0 GPIO_ResetBits(GPIOB, GPIO_Pin_12) 8 #define DACO_1 GPIO_SetBits(GPIOB, GPIO_Pin_11)//P2^3,´®ÐÐÊý¾ÝÏß½ÓÔÚD1Òý½ÅÉÏ 9 #define DACO_0 GPIO_ResetBits(GPIOB, GPIO_Pin_11) 10 #define REST_1 GPIO_SetBits(GPIOB, GPIO_Pin_10)//P2^0,¸´Î»Ïß½ÓÔÚRESTÉÏ 11 #define REST_0 GPIO_ResetBits(GPIOB, GPIO_Pin_10) 12 uchar OLED_GRAM[128][8]; 13 const uchar F14x16_Idx[17] = 14 { 15 "ÂííµÆÁÄ»²âÊÔ¿ªÊ¼" 16 }; 17 const uchar F14x16[] = 18 { 19 0x00,0x00,0x00,0x04,0xFC,0x04,0x04,0x04,0x84,0x7C,0x00,0x00,0x00,0x00, 20 0x00,0x00,0x08,0x08,0x08,0x09,0x09,0x09,0x08,0xC5,0x49,0x3F,0x00,0x00,/*"Âí",0*/ 21 0x00,0x00,0x40,0x28,0x98,0x40,0xF4,0x0A,0x18,0xA8,0x24,0x40,0x00,0x00, 22 0x00,0x32,0x4E,0xC2,0x7F,0x5A,0x31,0x4E,0x42,0x7F,0x0C,0x12,0x21,0x00,/*"íµ",1*/ 23 0x00,0x00,0xFE,0x14,0x94,0x94,0xF4,0x94,0x94,0xF4,0xB4,0x9C,0x00,0x00, 24 0x00,0x30,0x0F,0x84,0x44,0x34,0x0F,0x04,0x04,0x7F,0x04,0x04,0x04,0x00,/*"ÆÁ",2*/ 25 0x00,0x04,0x04,0xF4,0xB4,0xAE,0xB4,0xB4,0xAE,0xAC,0xF4,0x04,0x04,0x00, 26 0x00,0x08,0x0A,0x36,0x0A,0x09,0x7E,0x0A,0x0A,0x7A,0x0E,0x0A,0x09,0x00,/*"Ä»",3*/ 27 0x00,0x20,0x04,0xC0,0xFC,0x04,0xF4,0x04,0xFC,0x00,0xF0,0xFC,0x00,0x00, 28 0x00,0x00,0x7F,0x40,0x27,0x18,0x07,0x10,0x67,0x00,0x0F,0x7F,0x00,0x00,/*"²â",4*/ 29 0x00,0x80,0x8C,0x90,0x20,0x20,0x20,0x20,0xA0,0xFE,0x20,0x2C,0x10,0x00, 30 0x00,0x00,0x00,0x7F,0x18,0x20,0x21,0x1F,0x10,0x13,0x0C,0x30,0x70,0x00,/*"ÊÔ",5*/ 31 0x00,0x84,0x84,0x84,0xFC,0x84,0x84,0x84,0x84,0xFC,0x84,0x86,0x80,0x00, 32 0x00,0x40,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,/*"¿ª",6*/ 33 0x00,0x00,0xF0,0x2E,0xA0,0x70,0x40,0x70,0x4C,0x42,0x40,0x50,0xE0,0x00, 34 0x00,0x43,0x24,0x18,0x0F,0x30,0x00,0x7E,0x42,0x42,0x42,0x7F,0x02,0x00,/*"ʼ",7*/ 35 }; 36 /*const uchar F14x16_Idx[21] = //ÿ¸öºº×ÖÕ¼Á½¸ö×Ö½Ú£¬Ã¿¸ö×Ö·û´®×îºóÃ涼ÓÐÖÕÖ¹·û\n£¬ÖÕÖ¹·ûΪcharÐÍÕ¼Ò»¸ö×Ö½Ú 37 { //ËùÒÔ£¬ucharÐÍÊý×éµÄÊý×éÔªËظöÊý=ºº×Ö¸öÊý*2×Ö½Ú+1¸öÖÕÖ¹·û×Ö½Ú=21 38 "ÐÅÒâµç×ӿƼ¼ÆÁÄ»²âÊÔ" //¸ÃÊý×éÓõÄÊÇunsigned charÐÍ£¬ËùÒÔÿ¸öÊý×éÔªËصı仯·¶Î§ÊÇ0~255 39 }; 40 const uchar F14x16[] = 41 { 42 0x00,0x80,0xE0,0x1C,0x12,0x10,0x50,0x52,0x4C,0x50,0x50,0x30,0x08,0x00, 43 0x01,0x00,0x7F,0x00,0x00,0x01,0x7D,0x45,0x45,0x45,0x45,0x7C,0x00,0x00,//"ÐÅ",0 44 0x00,0x20,0x20,0xA8,0xA8,0xB8,0xA6,0xA8,0xB8,0x68,0xA8,0x20,0x20,0x00, 45 0x00,0x40,0x30,0x0F,0x76,0x46,0x4E,0x56,0x46,0x76,0x17,0x10,0x60,0x00,//"Òâ",1 46 0x00,0x00,0xF0,0x90,0x90,0x90,0xFE,0x90,0x90,0x90,0xF0,0x10,0x00,0x00, 47 0x00,0x00,0x0F,0x08,0x08,0x08,0x7F,0x48,0x48,0x48,0x4F,0x50,0x60,0x00,//"µç",2 48 0x00,0x00,0x04,0x04,0x04,0x04,0x04,0xE4,0x14,0x0C,0x04,0x84,0x80,0x00, 49 0x00,0x00,0x01,0x01,0x01,0x41,0x41,0x3F,0x01,0x01,0x01,0x00,0x00,0x00,//"×Ó",3 50 0x00,0x00,0x48,0xFC,0x44,0x42,0x00,0x88,0x30,0x00,0xFE,0x02,0x00,0x00, 51 0x00,0x0C,0x02,0x7F,0x01,0x01,0x08,0x08,0x05,0x04,0xFF,0x04,0x02,0x00,//"¿Æ",4 52 0x00,0x00,0x20,0xFE,0x20,0x90,0x20,0x20,0x20,0xFE,0x20,0xA0,0x10,0x00, 53 0x00,0x02,0x41,0x7F,0x81,0x80,0x41,0x47,0x29,0x18,0x27,0x41,0x40,0x00,//"¼¼",5 54 0x00,0x00,0xFE,0x14,0x14,0x34,0x54,0x14,0x94,0x74,0x14,0x9C,0x00,0x00, 55 0x00,0x30,0x0F,0x88,0x48,0x39,0x0F,0x09,0x08,0x7F,0x09,0x04,0x04,0x00,//"ÆÁ",6 56 0x00,0x04,0x04,0xF4,0x54,0xCE,0x54,0x54,0x4E,0x4C,0xF4,0x04,0x04,0x00, 57 0x00,0x08,0x0A,0x3E,0x0A,0x09,0x7E,0x0A,0x0A,0x7A,0x0E,0x0A,0x09,0x00,//"Ä»",7 58 0x00,0x20,0x04,0x80,0xFC,0x04,0xF4,0x04,0xFC,0x00,0xF0,0xFC,0x00,0x00, 59 0x00,0x00,0x7F,0x40,0x27,0x18,0x07,0x10,0x67,0x00,0x4F,0xFF,0x00,0x00,//"²â",8 60 0x00,0x80,0x88,0x98,0x20,0x20,0x20,0x20,0xA0,0xFE,0x24,0x2C,0x10,0x00, 61 0x00,0x00,0x1F,0x60,0x10,0x28,0x21,0x1F,0x10,0x13,0x1C,0x20,0x70,0x00,//"ÊÔ",9 62 };*/ 63 const uchar F8X16[]= 64 { 65 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 66 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1 67 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2 68 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3 69 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4 70 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5 71 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6 72 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7 73 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8 74 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9 75 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10 76 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11 77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12 78 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13 79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14 80 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15 81 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016 82 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117 83 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218 84 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319 85 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420 86 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521 87 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622 88 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723 89 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824 90 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925 91 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26 92 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27 93 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28 94 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29 95 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30 96 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31 97 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32 98 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33 99 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34 100 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35 101 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36 102 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37 103 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38 104 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39 105 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40 106 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41 107 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42 108 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43 109 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44 110 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45 111 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46 112 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47 113 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48 114 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49 115 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50 116 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51 117 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52 118 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53 119 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54 120 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55 121 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56 122 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57 123 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58 124 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59 125 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60 126 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61 127 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62 128 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63 129 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64 130 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65 131 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66 132 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67 133 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68 134 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69 135 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70 136 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71 137 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72 138 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73 139 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74 140 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75 141 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76 142 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77 143 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78 144 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79 145 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80 146 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81 147 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82 148 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83 149 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84 150 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85 151 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86 152 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87 153 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88 154 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89 155 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90 156 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91 157 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92 158 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93 159 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94 160 }; 161 const unsigned char F6x8[][6] = //±ê×¼ASCII×Ö·û´® 162 { 163 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //sp0 164 { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !1 165 { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "2 166 { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #3 167 { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $4 168 { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %5 169 { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &6 170 { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '7 171 { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (8 172 { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )9 173 { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *10 174 { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +11 175 { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,12 176 { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -13 177 { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .14 178 { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /15 179 { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 016 180 { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 117 181 { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 218 182 { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 319 183 { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 420 184 { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 521 185 { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 622 186 { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 723 187 { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 824 188 { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 925 189 { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :26 190 { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;27 191 { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <28 192 { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =29 193 { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >30 194 { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?31 195 { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @32 196 { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A33 197 { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B34 198 { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C35 199 { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D36 200 { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E37 201 { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F38 202 { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G39 203 { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H40 204 { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I41 205 { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J42 206 { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K43 207 { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L44 208 { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M45 209 { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N46 210 { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O47 211 { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P48 212 { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q49 213 { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R50 214 { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S51 215 { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T52 216 { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U53 217 { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V54 218 { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W55 219 { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X56 220 { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y57 221 { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z58 222 { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [59 223 { 0x00, 0x02, 0x04, 0x08, 0x10, 0x20 }, // \60 224 { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]61 225 { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^62 226 { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _63 227 { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '64 228 { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a65 229 { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b66 230 { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c67 231 { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d68 232 { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e69 233 { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f70 234 { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g71 235 { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h72 236 { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i73 237 { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j74 238 { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k75 239 { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l76 240 { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m77 241 { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n78 242 { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o79 243 { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p80 244 { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q81 245 { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r82 246 { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s83 247 { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t84 248 { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u85 249 { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v86 250 { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w87 251 { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x88 252 { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y89 253 { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z90 254 { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines91 255 }; 256 void init_OLED(void) 257 { 258 OLED_IO_Config(); 259 REST_0; 260 SCLK_1; 261 delay_ms(10); 262 REST_1; 263 OLED_writecom(0xae); OLED_writecom(0x00); 264 OLED_writecom(0x10); OLED_writecom(0x40); 265 OLED_writecom(0xcf); OLED_writecom(0xa1); 266 OLED_writecom(0xc8); OLED_writecom(0xa6); 267 OLED_writecom(0xa8); OLED_writecom(0x3f); 268 OLED_writecom(0xd3); OLED_writecom(0x00); 269 OLED_writecom(0xd5); OLED_writecom(0x80); 270 OLED_writecom(0xd9); OLED_writecom(0xf1); 271 OLED_writecom(0xda); OLED_writecom(0x12); 272 OLED_writecom(0xdb); OLED_writecom(0x40); 273 OLED_writecom(0x20); OLED_writecom(0x02); 274 OLED_writecom(0x8d); OLED_writecom(0x14); 275 OLED_writecom(0xa4); OLED_writecom(0xa6); 276 OLED_writecom(0xaf); OLED_Fill(0x00); 277 OLED_Set_Pos(0,0); 278 } 279 void OLED_IO_Config(void) 280 { 281 GPIO_InitTypeDef GPIO_InitStructure; //¶¨ÒåGPIO½á¹¹Ìå 282 283 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//ʹÄÜGPIOA¡¢GPIOB¿ÚʱÖÓ 284 285 /*½«PB0,PB1ÅäÖÃΪÍÆÍìÊä³ö*/ 286 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_1|GPIO_Pin_10;//PB1¡¢PB0 287 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö 288 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MʱÖÓËÙ¶È 289 GPIO_Init(GPIOB, &GPIO_InitStructure); 290 291 } 292 void OLED_writedat(uchar data) 293 { 294 uchar i = 8; 295 DC_1; 296 SCLK_0; 297 while (i--) 298 { 299 if (data & 0x80)//È¡×î¸ßλ 300 { 301 DACO_1; 302 } 303 else 304 { 305 DACO_0; 306 } 307 SCLK_1; 308 delay_us(1); 309 SCLK_0; 310 data <<= 1; 311 } 312 return; 313 } 314 void OLED_writecom(uchar com) 315 { 316 unsigned char i = 8; 317 DC_0; 318 SCLK_0; 319 while (i--) 320 { 321 if (com & 0x80) 322 { 323 DACO_1; 324 } 325 else 326 { 327 DACO_0; 328 } 329 SCLK_1;//ϽµÑØÊäÈëÐźŠ330 delay_us(1); 331 SCLK_0; 332 com <<= 1;//ÒÆλÊäÈë 333 } 334 335 return; 336 } 337 /*void OLED_display_on(void)//¿ªÆôOLEDÏÔʾ 338 { 339 OLED_writecom(0x8d);//µçºÉ±ÃÉèÖ㬱ØÐë³õʼ»¯ 340 OLED_writecom(0x14);//ÉèÖøßËÄλµÄµØÖ· 341 OLED_writecom(0xaf);//ÉèÖÃÏÔʾ¿ª¹Ø£¬¼´X0=1¿ªÆôÏÔʾ 342 } 343 void OLED_display_off(void)//¹Ø±ÕOLEDÏÔʾ 344 { 345 OLED_writecom(0x8d);//µçºÉ±ÃÉèÖ㬱ØÐë³õʼ»¯ 346 OLED_writecom(0x14);//ÉèÖøßËÄλµÄµØÖ· 347 OLED_writecom(0xae);//ÉèÖÃÏÔʾ¿ª¹Ø£¬¼´X0=0¿ªÆôÏÔʾ 348 } 349 void OLED_clear(void)//ÇåÆÁº¯Êý 350 { 351 for(uchar i=0;i<8;i++) 352 for(uchar n=0;i<128;i++) 353 OLED_GRAM[n][i]=0xff; 354 OLED_refresh();//¸üÐÂÏÔʾ 355 } 356 void OLED_drawpoint(uchar x,uchar y,uchar CF)//¸Ä±äÁËOLED_SRAMÖÐijһ¸öÔªËصÄ1bitÊý¾Ý£¬¼´¸Ä±äÁËÒ»¸öÏñËصãµÄÏÔʾ״̬ 357 { 358 uchar POS,BX,TEMP; 359 if(x>127||y>63) return;//³¬³öÏÔʾ·¶Î§ 360 POS=7-y/8; 361 BX=y%8; 362 TEMP=1<<(7-BX); 363 if(CF) OLED_GRAM[x][POS]|=TEMP; 364 else OLED_GRAM[x][POS]&=~TEMP; 365 } 366 void OLED_fill_dig(uchar X0,uchar Y0,uchar X1,uchar Y1,uchar CF)//ÔÚOLEDÉϻֱÏß 367 { 368 for(uchar i=X0;i<=X1;i++) 369 for(uchar j=Y0;j<Y1;j++) 370 { 371 OLED_drawpoint(i,j,CF); 372 } 373 OLED_refresh(); 374 } 375 void OLED_refresh(void) 376 { 377 for(uchar i=0;i<8;i++) 378 { 379 OLED_writecom(0xb0+i);//ÉèÖõØÖ·Ò³£¬Öð´ÎµÝÔö 380 OLED_writecom(0x02);//дÏÔʾλÖ᪡ªÁе͵ØÖ·£¬Æ«ÒÆÁ½ÁÐ 381 OLED_writecom(0x10);//дÏÔʾλÖ᪡ªÁиߵØÖ· 382 for(uchar n=0;n<128;n++) 383 OLED_writedat(OLED_GRAM[n][i]); 384 } 385 }*/ 386 void OLED_CLS(void)//¸´Î»º¯Êý 387 { 388 unsigned char y,x; 389 for(y=0;y<8;y++) 390 { 391 OLED_writecom(0xb0+y); 392 OLED_writecom(0x01); 393 OLED_writecom(0x10); 394 for(x=0;x<128;x++) 395 OLED_writedat(0); 396 } 397 } 398 void OLED_Fill(uchar bmp_dat)//ÉèÖÃOLEDÏÔʾȫÆÁ·ñ (¿ÉÓÃ×÷ÇåÆÁ) 399 { 400 unsigned char y,x; 401 for(y=0;y<8;y++) 402 { 403 OLED_writecom(0xb0+y); 404 OLED_writecom(0x01); 405 OLED_writecom(0x10); 406 for(x=0;x<128;x++) 407 OLED_writedat(bmp_dat); 408 } 409 } 410 void OLED_Set_Pos(uchar x, uchar y) //ÉèÖÃ×ø±êλÖà 411 { 412 OLED_writecom(0xb0+y); 413 OLED_writecom(((x&0xf0)>>4)|0x10); 414 OLED_writecom((x&0x0f)|0x01); 415 } 416 void OLED_P6x8Str(uchar x,uchar y,uchar ch[])//±ê×¼ASCII×Ö·û´®ÏÔʾº¯Êý 417 { //´Ëº¯Êý×ÓÓÃÀ´ÏÔʾASCII×Ö·û´® 418 uchar c=0,i=0,j=0; 419 while (ch[j]!='\0') //×Ö·û´®ÅжÏÊÇ·ñ½áÊø 420 { 421 c=ch[j]-32;// 422 if(x>122) {x=0;y++;} //µ±ÏÔʾʱ£¬ºáÐг¬¹ý128ʱ¾Íתµ½ÏÂÒ»ÐÐy++¡£ 423 OLED_Set_Pos(x,y); //ÉèÖÃÊä³öλÖÃ×ø±ê 424 for(i=0;i<6;i++) 425 OLED_writedat(F6x8[c][i]); //дÊý¾Ý£¨Ò»ÐдúÂë´ú±íÒ»¸öASCIIÂëÖµ£© 426 x+=6;//ÿ¸öASCIIÕ¼¾Ý6*8¸öÏñËص㣬ËùÒÔ¼Ó6 427 j++; 428 } 429 } 430 void OLED_P6x8Char(uchar X, uchar Y,uchar Data)//ÏÔʾһ¸ö×Ö·ûµÄº¯Êý 431 { 432 uchar i,ucDataTmp; 433 ucDataTmp=Data-32; 434 if(X > 122) 435 { 436 X = 0; 437 Y++; 438 } 439 OLED_Set_Pos(X,Y); 440 for(i=0;i<6;i++) 441 { 442 OLED_writedat(F6x8[ucDataTmp][i]); 443 } 444 } 445 void OLED_P8x16Str(uchar X,uchar Y,uchar ucDataStr[]) 446 { 447 uchar i,j,ucDataTmp; 448 Y<<=1; 449 for (j=0;ucDataStr[j]!='\0';j++) 450 { 451 ucDataTmp=ucDataStr[j]-32; 452 if(X>120)//ÿ¸ö×Ö·ûÕ¼ÓõÄÏñËصãÊýΪx=8£»y=16 453 { 454 X=0; 455 Y+=2; 456 } 457 OLED_Set_Pos(X,Y); 458 for(i = 0; i < 8; i++) 459 { 460 OLED_writedat(F8X16[(ucDataTmp << 4) + i]); 461 } 462 OLED_Set_Pos(X,Y+1); 463 for(i=0;i<8;i++) 464 { 465 OLED_writedat(F8X16[(ucDataTmp << 4) + i + 8]); 466 } 467 X+=8; 468 } 469 return; 470 } 471 void OLED_P14x16Str(uchar X,uchar Y,uchar ucDataStr[])//ÏÔʾºº×Öº¯Êý£¬´Ëº¯Êý½«Ò»¸öºº×Ö´ÓÉÏÏ·ÖΪÁ½°ëÀ´ 472 { //дÈëµ½OLEDÖУ¬Ã¿°ë¸öºº×ÖÓÉ14¸ö×ÖÄ£Êý×éÖеÄÔªËØ 473 uchar i, j; //À´ÃèÊö£¬Òò´ËÒªÉèÖÃÁ½´ÎSET_POS²Å¿ÉÒÔ 474 unsigned short usAddress; 475 Y <<= 1;//¸ø×ø±êY³ËÒÔ¶þ£¬´Ó¶øÕýÈ·È·¶¨ÏÔʾλÖà 476 j = 0; 477 while(ucDataStr[j]!='\0')//ÅжÏÊÇ·ñÏÔʾÍê±Ï 478 { 479 i = 0; 480 usAddress = 1; 481 while(F14x16_Idx[i] > 127)//ÿ¸öÊý×éµÄ±ä»¯·¶Î§ÊÇ£º0~225£¨unsigned charÐÍ£© 482 { 483 if(F14x16_Idx[i] == ucDataStr[j])//ÿ¸öºº×ÖÊÇÓÉÁ½¸ö×Ö½Ú£¨charÐÍ£©×é³ÉµÄ 484 { 485 if(F14x16_Idx[i + 1] == ucDataStr[j + 1])//Á½´ÎifÓï¾äÈ·ÈÏÁ˵ÚiλµÄÁ½Î»ºº×ÖÏàͬ 486 { 487 usAddress = i * 14; //µÚiλºº×Ö*14µÃµ½µØÖ·usAddress 488 break;//Ìø³öbreakËùÊôÑ»·£¬¼´ÎªÄÚ²ãµÄwhile£¨...>127£© 489 } 490 } 491 i += 2;//i×Ô¼Ó2£¬Ìøµ½ÏÂһλºº×ֵijõʼµØÖ· 492 } 493 if(X > 114)//ÏÖÔÚÒ»¸öºº×ÖËùÕ¼ÓеÄÏñËصãÊýΪ14*16¸ö 494 { 495 X = 0; 496 Y += 2;//YÔÚOLED_set_POSÖеĵ¥Î»²½½øΪ1¸ö×Ö½Ú£¨8룩£¬ÏÖÔÚÿ¸öºº×Ö¸ßλ16bit£¬ËùÒÔ¡£¡£ 497 } 498 if(usAddress != 1)// ÏÔʾºº×Ö 499 { 500 OLED_Set_Pos(X,Y);//ÏÔʾÉÏ°ë¿éºº×Ö 501 for(i =0; i<14;i++) 502 { 503 OLED_writedat(F14x16[usAddress]); 504 usAddress++; 505 } 506 OLED_Set_Pos(X,Y+1);//ÏÔʾÏ°ë¿éºº×Ö 507 for(i = 0;i < 14;i++) 508 { 509 OLED_writedat(F14x16[usAddress]); 510 usAddress++; 511 } 512 j += 2; 513 } 514 else //ÏÔʾ¿Õ°××Ö·û 515 { 516 OLED_Set_Pos(X,Y); 517 for(i = 0;i < 14;i++)//дÁËÒ»¸öÊý×ֵĿí¶È¾Í½áÊø 518 { 519 OLED_writedat(0); 520 } 521 OLED_Set_Pos(X,Y+1);//ÔÚÏÂÒ»Ò³¼ÌÐøд 522 for(i = 0;i < 14;i++) 523 { 524 OLED_writedat(0); 525 } 526 j++; 527 } 528 X+=14;//ÿִÐÐÒ»´ÎwhileµÄÍâÑ»·£¬x¶¼»á¼Ó14£¬ÒòΪÿ¸öºº×Ö¿í¶È14 529 } 530 return; 531 } 532 void OLED_PrintChar(uchar ucIdxX,uchar ucIdxY,unsigned short cData)//ÏÔʾunsigned shortÐÍËù¶ÔÓ¦µÄÊý×Ö 533 { 534 unsigned short i, j, k, usData; 535 536 if(cData < 0) 537 { 538 OLED_P6x8Char(ucIdxX, ucIdxY, '-'); 539 usData = (unsigned short)(-cData); 540 } 541 else 542 { 543 OLED_P6x8Char(ucIdxX, ucIdxY, '+'); 544 usData = (unsigned short)cData; 545 } 546 i = usData / 100; 547 j = (usData % 100) / 10; 548 k = usData % 10; 549 550 OLED_P6x8Char(ucIdxX+6, ucIdxY, i+48);//iÊÇcharÐÍÊý¾Ý+48Ö®ºó±ä³ÉASCIIÖеÄDECÊ®½øÖÆÊý¾Ý 551 OLED_P6x8Char(ucIdxX+12, ucIdxY, j+48); 552 OLED_P6x8Char(ucIdxX+18, ucIdxY, k+48); 553 return; 554 }
OLED.h
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #define uint unsigned int 2 #define uchar unsigned char 3 void OLED_IO_Config(void); 4 void init_OLED(void); 5 void OLED_writedat(uchar data); 6 void OLED_writecom(uchar com); 7 void OLED_display_on(void); 8 void OLED_display_off(void); 9 void OLED_clear(void); 10 void OLED_drawpoint(uchar x,uchar y,uchar CF); 11 void OLED_fill_dig(uchar X0,uchar Y0,uchar X1,uchar Y1,uchar CF); 12 void OLED_refresh(void); 13 void OLED_CLS(void); 14 void OLED_Set_Pos(uchar x,uchar y); 15 void OLED_Fill(uchar bmp_dat); 16 void OLED_P6x8Str(uchar x,uchar y,uchar ch[]); 17 void OLED_Set_Pos(uchar x, uchar y); 18 void OLED_P6x8Char(uchar X, uchar Y,uchar Data); 19 void OLED_P8x16Str(uchar X,uchar Y,uchar ucDataStr[]); 20 void OLED_P14x16Str(uchar X,uchar Y,uchar ucDataStr[]); 21 void OLED_PrintChar(uchar ucIdxX,uchar ucIdxY,unsigned short cData);
stm32f10x_it.c
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
1 #include "stm32f10x_it.h" 2 #include "USART.h" 3 #include "app.h" 4 #include "oled.h" 5 6 extern unsigned char Return[1000]; 7 extern unsigned char Count; 8 9 void USART2_IRQHandler(void) 10 { 11 if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) 12 { 13 Return[Count]= USART2->DR; 14 Count+=1; 15 if(Count>=200) Count = 0; 16 } 17 }
直接使用USB-TLL串口模块来操作,AT指令和主机端的设置一样
使用EasyTCP软件来连接ESP8266的设备,IP地址通过查看OLED显示的信息为192.168.4.1,端口设置为333,所以连接的结果如下
程序中通过发送2来开启STM32上的LED,相反通过发送3来关闭STM32上的LED!
NodeMCU简单使用(2017-04-26):
今天买了块小板子本来是用来买个完整的,所有GPIO都接粗来的ESP8266的板子来玩的,结果没啥资料,看某宝下面的资料就给了个链接,点进去一看全英文...(NodeMCU官网),呀呀呀还不错啊Lua语言开发ESP8266,这玩意贼溜,于是就网上找了找这方面的资料,不得不说的是这ESP8266小芯片不愧称为 麻雀虽小五脏俱全啊~参照这网站入门NodeMCU真棒~ http://benlo.com/esp8266/esp8266QuickStart.html
NodeMCU固件程序源代码:https://github.com/nodemcu/nodemcu-firmware
下面是在CSDN的博主发布的文章,感觉入门很好~(链接如下:http://blog.csdn.net/dingzz/article/details/46876503)
1 wifi.setmode(wifi.STATION) 2 wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD") 3 print(wifi.sta.getip()) 4 led1 = 0 5 led2 = 4 6 gpio.mode(led1, gpio.OUTPUT) 7 gpio.mode(led2, gpio.OUTPUT) 8 srv=net.createServer(net.TCP) 9 srv:listen(80,function(conn) 10 conn:on("receive", function(client,request) 11 local buf = ""; 12 local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); 13 if(method == nil)then 14 _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); 15 end 16 local _GET = {} 17 if (vars ~= nil)then 18 for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do 19 _GET[k] = v 20 end 21 end 22 buf = buf.."<h1> ESP8266 Web Server</h1>"; 23 buf = buf.."<p>GPIO16 <a href=\"?pin=ON1\"><button>OFF</button></a> <a href=\"?pin=OFF1\"><button>ON</button></a></p>"; 24 buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>OFF</button></a> <a href=\"?pin=OFF2\"><button>ON</button></a></p>"; 25 local _on,_off = "","" 26 if(_GET.pin == "ON1")then 27 gpio.write(led1, gpio.HIGH); 28 elseif(_GET.pin == "OFF1")then 29 gpio.write(led1, gpio.LOW); 30 elseif(_GET.pin == "ON2")then 31 gpio.write(led2, gpio.HIGH); 32 elseif(_GET.pin == "OFF2")then 33 gpio.write(led2, gpio.LOW); 34 end 35 client:send(buf); 36 client:close(); 37 collectgarbage(); 38 end) 39 end)
我们将以上代码的第二行的YOUR_NETWORK_NAME与YOUR_NETWORK_PASSWORD分别替换成我们自己的无线热点的名称和密码,然后通过LuaLoader程序调试工具的Upload FIle...按钮来上传到NodeMcu板子,最后按dofile执行刚才上传的程序。
代码稍有改动,可能我和CSDN版主的芯片的外围电路不同吧,主要改了HTML部分的按键部分,还有就是按键的接口(0--->GPIO16 & 4--->GPIO2),下面是我的购买链接:https://detail.tmall.com/item.htm?id=44766400092&spm=a1z09.2.0.0.WdMqyB&_u=q1gpmsvhc513
看看实物图吧~(想想再使用之前介绍的花生壳域名来做个内网透传就阔以使用外网来访问控制这个超小型的Web Server啦!!)