51 microcontroller is the collective name for all microcontrollers compatible with the Intel 8031 instruction system. The ancestor of this series of microcontrollers is Intel's 8004 microcontroller. Later, with the development of Flash rom technology, the 8004 microcontroller made great progress and became one of the most widely used 8-bit microcontrollers. Its representative model is the AT89 series of ATMEL Company. It is widely used in industrial measurement and control systems. Many companies have launched compatible models of the 51 series, which will occupy a large market for a long time in the future. The 51 microcontroller is a basic entry-level microcontroller, and it is also the most widely used one. It should be noted that 51 series microcontrollers generally do not have self-programming capabilities.
51 microcontroller difference
The same program will produce the same result when running on the hardware of various microcontroller manufacturers, such as ATMEL's 89C51 (discontinued), 89S51, PHILIPS, and WINBOND, etc. The 89C51 that we often say has been discontinued refers to ATMEL. The AT89C51 microcontroller has enhanced many features on the original basis, such as clock. What's even better is that the original ROM (one-time write) is replaced by Flash (the contents of the program memory can be rewritten at least 1000 times). The performance of AT89C51 It is very superior to 8051.
However, in terms of marketization, 89C51 has been challenged by the PIC microcontroller camp. The most fatal flaw of 89C51 is that it does not support ISP (online update program) function. New functions such as ISP function must be added to better continue the legend of MCS-51.
It is against this background that 89S51 replaced 89C51. 89S51 has become the new darling in the practical application market. Atmel, which has the largest market share, has discontinued AT89C51 and will replace it with AT89S51. 89S51 has been improved in the process. 89S51 adopts 0.35 new process, which reduces the cost and improves the functions to increase its competitiveness. 89SXX is backward compatible with 51 series chips such as 89CXX. At the same time, Atmel no longer accepts orders for 89CXX. The 89C51 you see on the market is actually a huge inventory of Atmel's early production. If the market demands it, Atmel can of course resume production of AT89C51.
51 microcontroller connects to ESP8266 serial port WiFi module
Pin connection
Burn firmware
Open the burning software, select the configuration tab, and click the small gear icon in the second column - load the firmware address
Click the selection bar for other options, uncheck it, and select only the second option (firmware address)
Return to the operation tab, select the correct COM port, and click one-click programming
The module is powered on again, the download starts, and waits for the download to complete.
Serial port assistant tests ESP8266 serial port WiFi module
Pin connection
Note: At this time, the connection status is WiFi module - "51 microcontroller -" serial port assistant (PC). Since the TXD and RXD of the WiFi module and the microcontroller are in a positive connection state, the microcontroller and the WiFi module do not communicate, which is equivalent to the WiFi module being directly connected to the serial port assistant.
AT common commands
The ESP8266 serial WiFi module is divided into three working modes: Station mode (similar to a wireless terminal), AP mode (providing wireless access services), and AP mode and Station mode.
When testing the WiFi module through the serial port assistant,
test
Send command: AT
Response: OK
Restart module
Send command: AT+RST
Response: OK
Setup module
Send command: AT+CWMODE = "mode"
Note: It takes effect after restarting (AT+RST)
"mode": 1-Station mode, 2-AP mode, 3-AP and Station mode.
Response: OK
Configure AP parameters
send command:
Command: AT+ CWSAP= "ssid", "pwd", "chl", "ecn"
Note: The command is only valid after the AP mode is turned on.
"ssid": string parameter, access point name
"pwd": string parameter, password up to 64 bytes, ASCII
"chl": channel number
"ecn": encryption mode, 0-OPEN, 1-WEP, 2-WPA_PSK, 3-WPA2_PSK, 4-WPA_WPA2_PSK
Example: AT+CWSAP="TEST","123456123456",1,3
Response: OK
Turn on multi-connection mode
Send command: AT+CIPMUX=《mode》
Description: "mode": 0-single connection mode, 1-multiple connection mode
Response: OK
Create server
Send command: AT+CIPSERVER=《mode》,《port》
Note: The server can be turned on only when AT+ CIPMUX=1; turning off the server mode requires a restart. After opening the server, server monitoring is automatically established. When a client accesses, a connection will be automatically occupied in sequence.
"mode": 0-turn off server mode, 1-turn on server mode
"port": port number, the default value is 333
Response: OK
Initialize WiFi module through 51 microcontroller
By testing AT commands through the serial port assistant, you can find that some AT commands will not be saved when the power is turned off, so initialization settings need to be made in the code.
Pin connection
Note: At this time, the connection status is WiFi module - "51 microcontroller -" serial port assistant (PC). Since the TXD and RXD of the WiFi module and the microcontroller are in the positive connection state, the microcontroller and WiFi module can carry out serial communication.
Implement code
#include《reg52.h》 //Commonly used header files for 51 microcontrollers
#define uchar unsigned char //Macro defines an unsigned char type
#define uint unsigned int //Macro defines an unsigned int type
//Send one byte
void sendByte(float b)
{
SBUF = b;
while (!IF);
TI = 0;
}
//Send string
void sendString(uchar *s)
{
while (*s != '') //The default end of the string is '', to determine the end of the string
{
sendByte(*s);
s++;
}
}
//Initialize ESP8266WiFi module
void initEsp()
{
uint a;
SCON = 0x50; //8-bit data, variable baud rate
TMOD = 0x20; //Set the timer 1-bit 16-bit automatic reload mode
TL1 = 0xfd; //Set the initial value of the timer, the baud rate is 9600
TH1 = 0xfd;
ET1 = 0; //Disable timer 1 interrupt
TR1 = 1; //Start timer 1
EA = 1;
for (a=0; a<50000; a++); //Delay for a few seconds to allow the module time to start
sendString(“AT+CWMODE=2”); //Set to softAP and station coexistence mode
//WiFi hotspot cannot be set through code. You can use the serial port assistant to set it up. The settings will not be lost when the power is turned off.
/*
for (a=0; a《20000; a++);
sendString("AT+CWSAP='TEST','12345678',1,3"); //Establish WiFi hotspot
*/
for (a=0; a《50000; a++);
sendString(“AT+CIPMUX=1”); //Start multiple connections
for (a=0; a《20000; a++);
sendString("AT+CIPSERVER=1,333");//Establish server, port is 333
for (a=0; a《20000; a++);
sendString(“AT+CIPSTO=50”); //Server timeout setting
RI=0;
ES=1; //Initialization completed, serial port interrupt is opened
}
//Main function
void main()
{
initEsp();
}
Note: The baud rate in the code should match the baud rate of the serial port assistant, and some AT commands such as restarting the module and setting up WiFi hotspots cannot be used.
Get data transmitted by WiFi
As a TCP server, the ESP8266WiFi module will add +IPD, n, "string.length" by default before accepting information from the client: such characters should be paid attention to when processing.
Implement code
//Get data, data format example: +IPD, 0, 14: "time": "11:11"
void getData()
{
uint a;
if(receiveFlag)
{
for(i=0; i《2; i++)
{
Hour[i]=Buffer[17+i];
}
Hour[2]=‘’;
for(i=0; i《2; i++)
{
Minute[i]=Buffer[20+i];
}
Minute[2]=‘’;
//Send the obtained data to the serial port assistant for display
for (a=0; a<10000; a++); //Delay is required, which may cause data confusion and packet loss.
sendString(Hour);
for (a=0; a《10000; a++);
sendString(Minute);
receiveFlag=0;
count=0;
for(i=0; i《22; i++)
{
Buffer[i]=0;
}
}
}
//Main function
void main()
{
initEsp(); //Initialize WiFi module
receiveFlag = 0; //receiveFlag determines the flag for executing getData()
count = 0; //index of count buffer RXDdata[count]
while(1)
{
getData();
}
}
//Use interrupt to receive information and discard invalid information
void uart() interrupt 4
{
if(RI == 1)
{
ES = 0; //Turn off serial interrupt
RI = 0; //Clear the serial port receiving flag bit
temp = SBUF; //Get data from the serial port buffer
if(count<20) //Satisfy the length of information to be received and store the data in the buffer
{
Buffer[count]=temp;
count++;
if (Buffer[0]=='+') //Determine whether it is invalid data, because the WiFi module will automatically add a string starting with "+PID.."
{
receiveFlag = 1;
}
else
{
receiveFlag = 0;
count = 0;
}
}
ES = 1;
}
}
Previous article:Design and implementation of conductive material temperature measurement system
Next article:Design of temperature acquisition and display system based on AT89S51 microcontroller and LM35 temperature sensor
Recommended ReadingLatest update time:2024-11-15 07:56
- Popular Resources
- Popular amplifiers
- Build your own virtual machine: design and implementation of parsing programming languages
- IoT Development for ESP32 and ESP8266 with JavaScript (Peter Hoddie , Lizzie Prader)
- EXPLORE ESP32 MICROPYTHON Python Coding, Arduino Coding, Raspberry Pi, ESP8266, IoT Projects, Androi
- Electronics Projects with the ESP8266 and ESP32 Building Web Pages, Applications, and WiFi Enabled D
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [National Technology Low Power Series N32L43x Review] 02. Create a template project
- Altium Designer copper patch teardrop setting problem
- [Sipeed LicheeRV 86 Panel Review] 2- Board Resource Introduction and Data Collection
- How much do you know about fast charging? A collection of learning materials on fast charging technology and solutions
- Internal clock and RTOS system
- [Xianji HPM6750 Review 1] Experience with two IDE (SES and RS) development platforms
- BlueNRG-x Documentation - Copy and create your own projects
- Looking for a linear voltage regulator chip
- 【Paper】How to design broadband, efficient GaN RF power amplifiers
- Carbon dioxide gas sensor detection circuit