ESP8266 module adopts STA working mode. First, use the serial port debugging assistant on the computer to set the ESP8266 module to STA mode and baud rate 9600. The specific instructions are as follows:
1. Set AP mode AT+CWMODE=2
2. Reset takes effect AT+RST
3. Configure hotspot AT+CWSAP="test","12345678",1,3
In this way, even if ESP8266 is reset, this information will not be erased. You can directly use the following instructions to
connect the microcontroller to ESP8266. Be sure to pay attention to the common ground between the two, otherwise ESP8266 will not work properly. The ESP8266 power supply must be 3.3V, and 5V does not seem to work. The EN pin of ESP8266 is connected to a 1K ohm resistor and then to a 3.3V power supply.
#include
typedef unsigned char u8;
typedef unsigned int u16;
sbit LED = P1^0;u8 dat;
void Init(void); //Serial port initialization function
void Delay_ms(u16 n);//delay sub-function
void Sent_ZF(u8 dat);//send a byte
void AT_Send_String(u8 *string);//send string
void ESP8266_Init();//ESP8266 initialization
void Init(void) //Serial port initialization function
{
TMOD=0x20; //Timer working mode 2, 8-bit automatic reload (0010 0000)
TL1=0xfd; //Load initial value
TH1=0xfd;
TR1=1; //Start timer 1
REN=1; //Allow serial port to receive data
SM0=0; //Working mode 1, 10-bit asynchronous reception and transmission
SM1=1;
EA=1; //Open global interrupt control
ES=1; //Open serial port interrupt
}
void main()
{
Init();
ESP8266_Init();
while(1);
}
void Sent_ZF(u8 dat) //Send a byte
{
ES = 0;
TI=0;
SBUF = dat;
while(!TI);
TI = 0;
ES = 1;
}
void Delay_ms(u16 n) //Delay subroutine
{
unsigned int i,j;
for(i=0;i
}
void AT_Send_String(u8 *string) //Send string
{
while(*string!='')
{
Sent_ZF(*string);
string++;
Delay_ms(10);
}
}
void ESP8266_Init() //ESP8266 initialization
{
AT_Send_String("AT+RSTrn"); //Restart moduleDelay_ms
(10000);
Delay_ms(10000);
AT_Send_String("AT+CIPMUX=1rn"); //Set to multi-connection mode, start moduleDelay_ms
(10000);
Delay_ms(10000);
AT_Send_String("AT+CIPSERVER=1,8080rn"); //Server port setting
Delay_ms(10000);
Delay_ms(10000);
}
void InterruptUART() interrupt 4 //Control the small light switch
{
RI= 0; //Clear
dat= SBUF; //The received data is stored in SBUF
{
if(dat=='o')
{
LED =0;
}
if(dat=='f')
{
LED =1;
}
}
}
Download a software called Network Debug Assistant on your phone. The IP address is 192.168.4.1 (it seems to be the same port), and the port number is 8080. After the connection is successful, send f or o to control the LED light switch.
Previous article:Design of TB6560 two-phase hybrid stepper motor driver board
Next article:The serial port controls three digital tubes via 164
Recommended ReadingLatest update time:2024-11-15 14:49
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- May I ask if Mr. Yi Zhongtian mentioned in a certain program that he talked about "have you learned it?", "have you learned it thoroughly?", "have you learned it thoroughly?", in which program did he say this?
- PCB file conversion
- 5G indoor base stations will be released soon, and it is expected that each household will have a small base station, which will subvert the existing home Internet access methods.
- How to consider the impact of audio analog signals after being transmitted through a 100m long cable?
- Angle sensor
- Transistor Selection
- Fancy PCB Exhibition (1)
- Why is it said that 90% of EMC is designed? (Long article)
- Chinese mobile phones continue to sell well in India, Vivo surpasses Samsung to become the second largest brand
- Share CC2541 Bluetooth learning about ADC