C51: Implementing Software Reset with C51
Q:
How can I implement software reset in my source program?
A:
You can use the following program to jump to 0000H to implement soft reset. The following program is actually a function pointer, which points to the address 0000H.
((void (code *) (void)) 0x0000) ();
The following example will implement software self-reset void reset (void)
{
((void (code *) (void)) 0x0000) ();
}
void main (void)
{
reset ();
}
You may notice that the above soft reset program does not clear the 8051 interrupt system and some 8051 peripherals. When you call the above software reset program in the interrupt program, the interrupt will no longer be triggered. Therefore, the above soft reset program cannot be called in the interrupt subroutine. The following
small assembly function can be called in the interrupt program or the main program. The function pushes 0x0000 onto the stack and then pops it with "RETI". This will clear the interrupt environment and let the program restart from 0000H.
?PR?RESET SEGMENT CODE
RSEG ?PR?RESET
; C prototype: void reset (void);
PUBLIC reset
reset: POP ACC pop return address
POP ACC
CLR A push 0 as new
PUSH ACC return address to stack
PUSH ACC
RETI execute return of interrupt
END
The above program works well when bank 0 register group is selected. If the bank 0 register group is not selected, you may not get the expected results. You should add "MOV PSW, #0" in the above program or startup code to select bank 0 register group.
Reference address:How do I implement a software reset in my source program?
Q:
How can I implement software reset in my source program?
A:
You can use the following program to jump to 0000H to implement soft reset. The following program is actually a function pointer, which points to the address 0000H.
((void (code *) (void)) 0x0000) ();
The following example will implement software self-reset void reset (void)
{
((void (code *) (void)) 0x0000) ();
}
void main (void)
{
reset ();
}
You may notice that the above soft reset program does not clear the 8051 interrupt system and some 8051 peripherals. When you call the above software reset program in the interrupt program, the interrupt will no longer be triggered. Therefore, the above soft reset program cannot be called in the interrupt subroutine. The following
small assembly function can be called in the interrupt program or the main program. The function pushes 0x0000 onto the stack and then pops it with "RETI". This will clear the interrupt environment and let the program restart from 0000H.
?PR?RESET SEGMENT CODE
RSEG ?PR?RESET
; C prototype: void reset (void);
PUBLIC reset
reset: POP ACC pop return address
POP ACC
CLR A push 0 as new
PUSH ACC return address to stack
PUSH ACC
RETI execute return of interrupt
END
The above program works well when bank 0 register group is selected. If the bank 0 register group is not selected, you may not get the expected results. You should add "MOV PSW, #0" in the above program or startup code to select bank 0 register group.
Previous article:Examples of pointer functions
Next article:An efficient SPI analog read and write function
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
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- EEWORLD University Hall----GPS Principles and Applications
- Keil5 software simulation problem
- [ESP32 Learning_1] The first ESP32-S3 example - hello_world
- How TI dual-core processor ARM+DSP achieves collaborative work
- GD32F307VG supports Mbed development
- TMS320C6000 Basic Learning (1) - Understanding
- How to measure analog voltage using the ADC of MSP430?
- AD sampling has been used for so long, it's time to get familiar with the internal structure
- Solution: Vivado cannot find the ILA core, or finds the ILA but there is no corresponding data line in the window
- There are posts everywhere. Why hang it on a tree?