Please look at the program at the bottom first.
This is a program for Keil software, called "pure software" reset. The so-called "pure software" means that it does not directly operate hardware and registers.
In fact, if you don't understand hardware and assembly, you can't have this C program. Anyway, let's take a look at its true face:
We know that 51 microcontrollers
can put data in the program memory, that is, there is no essential difference between programs and data, they are all specific data. If we store a program in the form of array data in the program memory, can it be executed? The answer is yes.
-Now
back to the topic, let's take a look at the array data 0xe4, 0xc0, 0xe0, 0xc0, 0xe0, 0x22. From the assembly window of Keil, we can see that it is actually four assembly statements:
CLR A; compiled as 0XE4
PUSH ACC; compiled as 0XC0 0XE0
PUSH ACC; compiled as 0XC0 0XE0
RET; function return is compiled as 0X22. It can be seen that this is actually the assembly reset instruction of the 51 microcontroller.
In fact, it's just that the C reset code is written in an ugly way. rst is a byte pointer pointing to the program memory. We convert it to a pointer to a function that returns void. The format of a function pointer that returns void is: void
(*)(). This expression is more complicated because of the operator priority relationship. Enclose it in parentheses and it becomes (void
(*)())rst. In this way, rst becomes a function pointer. Let's take a look at the general format of function pointer (*p)(). Replace p with (void
(*)())rst and enclose it in parentheses to become (*((void (*)())rst))(). This reveals the whole veil of this reset.
The following is the test and verification program:
#include
main()
{
unsigned char code rst[6]={0xe4,0xc0,0xe0,0xc0,0xe0,0x22}; //Define an array of code type, it must be of code type
while(1) //Loop test
{
TMOD=5; //The test can be any language name
TI=1;
P1=0;
P1=1;
P2=2;
P3=3;
(*((void (*)())rst))(); //Reset
SCON=0x50;
}
}
Reference address:Software reset of 51 MCU
This is a program for Keil software, called "pure software" reset. The so-called "pure software" means that it does not directly operate hardware and registers.
In fact, if you don't understand hardware and assembly, you can't have this C program. Anyway, let's take a look at its true face:
We know that 51 microcontrollers
can put data in the program memory, that is, there is no essential difference between programs and data, they are all specific data. If we store a program in the form of array data in the program memory, can it be executed? The answer is yes.
-Now
back to the topic, let's take a look at the array data 0xe4, 0xc0, 0xe0, 0xc0, 0xe0, 0x22. From the assembly window of Keil, we can see that it is actually four assembly statements:
CLR A; compiled as 0XE4
PUSH ACC; compiled as 0XC0 0XE0
PUSH ACC; compiled as 0XC0 0XE0
RET; function return is compiled as 0X22. It can be seen that this is actually the assembly reset instruction of the 51 microcontroller.
In fact, it's just that the C reset code is written in an ugly way. rst is a byte pointer pointing to the program memory. We convert it to a pointer to a function that returns void. The format of a function pointer that returns void is: void
(*)(). This expression is more complicated because of the operator priority relationship. Enclose it in parentheses and it becomes (void
(*)())rst. In this way, rst becomes a function pointer. Let's take a look at the general format of function pointer (*p)(). Replace p with (void
(*)())rst and enclose it in parentheses to become (*((void (*)())rst))(). This reveals the whole veil of this reset.
The following is the test and verification program:
#include
main()
{
unsigned char code rst[6]={0xe4,0xc0,0xe0,0xc0,0xe0,0x22}; //Define an array of code type, it must be of code type
while(1) //Loop test
{
TMOD=5; //The test can be any language name
TI=1;
P1=0;
P1=1;
P2=2;
P3=3;
(*((void (*)())rst))(); //Reset
SCON=0x50;
}
}
Previous article:51 MCU PID algorithm implementation program C language
Next article:Crystal oscillator circuit in single chip microcomputer
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- 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
Guess you like
- MSP430F5529&LCD1602 Program
- Ultra-wideband technology: the nemesis of shadows and blind spots in wireless technology
- RF Basics - Professional Terminology
- MSP430 MCU Example 12-4X4 Matrix Keyboard Key Value Display
- Qorvo Online Design Conference-The new Wi-Fi 6 standard is changing the connectivity environment
- BLDC back EMF is a bit weird
- How do I set the impedance of the differential line in ALTIUM19?
- EEWORLD University Hall----Live Replay: Introduction to Keysight's New Optical Communication Test Solution
- A complete list of filter circuits, save it for future use!
- How to choose FPGA development board