Some single-chip microcomputers (such as 8098) have special reset instructions. Although some enhanced MCS-51 system single-chip microcomputers do not have reset instructions, they have integrated WATCHDOG circuits in the chip, so anti-interference is not a problem. Since the popular MCS-51 series single-chip microcomputers (such as 8031 and 8032) have no reset instructions and do not have hardware WATCHDOG circuits, if there is no external hardware WATCHDOG circuit, software anti-interference technology must be used. Commonly used software anti-interference technologies include: software traps, instruction redundancy, software WATCHDOG, etc. Their role is to detect when the system is interfered with in time, and then use software methods to reset the system. The so-called software reset is to use a series of instructions to imitate the reset operation. This is the software reset technology unique to the MCS-51 series single-chip microcomputers.
Now let's use a simple experiment to illustrate. The experimental circuit is shown in the attached figure. The light-emitting diode LED0 connected to the simulation socket P1.0 is used to indicate the working status of the main program, the light-emitting diode LED1 connected to P1.1 is used to indicate the working status of the low-level interrupt subroutine, the light-emitting diode LED2 connected to P1.2 is used to indicate the working status of the high-level interrupt subroutine, and the button connected to the P3.2 port is used to set up an interference flag. After the program detects the interference flag, it deliberately enters an infinite loop or falls into a trap to simulate the interference situation, thereby verifying the actual effects of various reset methods. The test initialization program is as follows:
ORG 0000H
STAT: LJMP MAIN; reset entry address
LJMP PX0; button interrupt vector (low-level interrupt)
ORG 000BH
LJMP PT0 ; t0 interrupt vector (low-level interrupt)
ORG 001BH
LJMP PT1; T1 interrupt vector (high-level interrupt)
ORG 0030H
MAIN:
CLR EA
MOV SP, #7
MOV P1,#0FFH
MOV P3,#0FFH
MOV TMOD,#11H
CLR 00H ;Interference flag initialization
SET B ET0
SETB ET1
SET EB OX0
SET PB PT 1
SET TB TR 0
SET TB TR 1
SETBB EA
LOOP: CPL P1.0; main program LED flashes
MOVR6,#8H
MOV R7, #0
TT1:
DJNZ R7, TT1
DJNZ R6, TT1
SJMP LOOP
PX0:
SET B 00H ; Set up interference flag to simulate interference
PT0: CPL P1.1 ;Low-level interrupt program LED LED1 flashes
RETI
PT1: CPL P1.2; Advanced interrupt program LED LED2 flashes
RETI
EN
The experimental steps are as follows:
1. Start the execution according to the above program, and all three LEDs should flash (otherwise, the fault should be eliminated first), indicating that the main program and each interrupt subroutine are normal. Because the analog interference mark is not detected, it is not affected by the button.
2. Modify the main program as follows. When the button is pressed, the main program falls into an infinite loop.
LOOP: CPL P1.0
MOVR6,#8H
MOV R7, #0H
TT1: DJNZ R7, TT1
DJNZ R6, TT1
JNB 00H,LOOP; Is there any interference?
STOP: LJMP STOP; fall into an infinite loop.
At this time, you can see that the main program stops working (LED0 stops flashing), while the two interrupt subroutines continue to run (LED1 and LED2 continue to flash).
3. Use timer T1 as software WATCHDOG and 30H unit as software WATCHDOG counter. Add a reset instruction of software WATCHDOG in the main program.
LOOP: CPL P1.0
MOV 30H, #0; reset software WATCHDODG counter
LOOP: CPL P1.0
MOVR6,#8H
MOV R7, #0H
TT1: DJNZ R7, TT1
DJNZ R6, TT1
JNB 00H,LOOP; Is there any interference?
STOP: LJMP STOP; fall into an infinite loop.
The T1 interrupt subroutine is modified as follows:
PT1: CPL P1.2; Advanced interrupt program LED flashes
INC 30H
MOV A, 30H
ADD A,#0FDH
JC ERRR; Has it reached 3 times?
RETI
ERR: LJMP STATUS; software WATCHDODG action
Before the button is pressed, the program runs normally (all three LEDs flash). After the button is pressed, the main program can quickly resume work, but the two interrupt subroutines are blocked and no longer work. The process is as follows: After the main program detects interference, it enters an infinite loop and cannot perform the operation of resetting the 30H unit. The T1 interrupt causes 30H to increase in value continuously. When the count reaches 3, the software WATCHDOG executes an action and executes an LJMP instruction to restart the program. The interference flag is cleared during the MAIN process (indicating that the interference has passed), so that the main program can quickly resume work. It stands to reason that the interrupts are also reset and opened during the MAIN process. Why can't the interrupts resume work? This is because the reset of the interrupt activation flag has been forgotten, because it has no clear bit address to be programmed, and directly turning to the 0000H address cannot complete the real reset. Software reset is a must-do after using software traps and software WATCHDOG. At this time, it is entirely possible that a program error occurs. In the interrupt subroutine, the interrupt activation flag is set, which will prevent the same-level interrupt response. Since software WATCHDOB is a high-level interrupt, it will block all interrupt responses. Therefore, it can be seen that clearing the interrupt activation flag is essential. Many authors of literature may have made mistakes because they did not realize this.
4. Among all the instructions, only RETI instruction can clear the interrupt activation flag. The error handling procedure ERR mainly completes this function, and other follow-up work is completed by the reset system. For this reason, we redesign the T1 interrupt subroutine as follows:
PT1: CPL P1.2; Advanced interrupt program LED flashes
INC 30H; software WATCHDOOG counter increments
MOV A, 30H
ADD A,#0FD
JC ERRR; Has it reached 3 times?
RETI
ERR: CLR EA; disable interrupt
CLR A; Prepare reset address (0000H)
PUSH ACC
PUSH ACC
RETI ; Clear interrupt activation flag and reset
This program first turns off the interrupt so that the subsequent processing can proceed smoothly, and then replaces the LJMP instruction with the RETI instruction, thereby clearing the interrupt activation flag and completing the task of turning to 0000H. After the program is run again after this modification, the result is still not ideal: after pressing the button, sometimes only the main program and the high-level interrupt subroutine can quickly return to normal, while the low-level interrupt may still be turned off. If the interference is transferred to the low-level interrupt as follows, the low-level interrupt will definitely be turned off after pressing the button:
LOOP: CPL P1.0
MOVR6,#8H
MOV R7, #0H
TT1: DJNZ R7, TT1
DJNZ R6, TT1
SJMP LOOP
PT0: CPL P1.1
JB 00H,STOP
RETI
STOP: LJMP STOP; fall into an infinite loop.
After careful analysis, we may conclude that when the software WATCHDOB is nested in a low-level interrupt, only the high-level interrupt activation flag is cleared after reset, and the low-level interrupt flag is still set, so that the low-level interrupt is always disabled.
5. Modify the error handling as follows:
ERR: CLR EA; Correct software reset entry
MOV 66H, #0AAH; Rebuild power-on flag
MOV 67H,#55H
MOV DPTR, #ERR1; prepare the first return address
PUSHDPL
PUSHD
RETI ; Clear the advanced interrupt activation flag
ERR1: CLRA
PUSH ACC
PUSH ACC
RETI ; Clear low-level interrupt activation flag
At this time, RETI must be executed twice to reach 0000H to ensure that all interrupt activation flags are cleared and achieve the same effect as hardware reset. Similarly, the software trap must also be executed by the following three instructions
NOP
NOP
LJMP STAT
To:
NOP
NOP
LJMP ERRR
To achieve the goal.
When the main program is disturbed and captured by the software trap, the interrupt flag is not set. During the execution of ERR, the RETI instruction is equivalent to the RET instruction, which can also achieve the purpose of software reset. Interested readers can replace the dead loop with the software trap, replace LJMP ERRR with LJMP STAT and LJMP ERRR1 respectively, and then set the interference detection in the low-level interrupt and the main program respectively. The experimental results will inevitably prove that only LJMP ERRR can achieve software reset without any mistakes, so that the system can get rid of interference and return to normal. In the software reset process of the MCS-51 microcontroller, the interrupt return instruction RETI must be executed twice in succession.
Previous article:A brief discussion on the functional application of TSS-5 single-board controller and the characteristics of MSP430
Next article:Precision32 chip solution introduction continues the advantages of 8-bit MCU
Recommended ReadingLatest update time:2024-11-16 21:30
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- Does anyone have the specification sheet of IP804 IP808 of Joyoung Electronics?
- Design principle of pressure level gauge.
- Share some methods for beginners to learn 430 microcontroller
- In a circuit powered by a 10V DC voltage source, a 4uF 6uF 1 ohm resistor is connected in series. What is the voltage of the two capacitors when the steady state is reached?
- Getting Started with TI CC1310 sub1G SDK Development
- Questions about phase shifting
- Free sharing of senior hardware engineer's video explanation---ADC analog-to-digital converter device design selection guide
- Explanation and correction of MSP430 MCU __delay_cycles precise delay
- The optocoupler is broken, I can't figure out the reason, please give me some advice
- Some information on Hall sensor applications