A Brief Discussion on the Software Reset Method of Single Chip Microcomputer

Publisher:创意航海Latest update time:2018-04-12 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

A Brief Discussion on the Software Reset Method of Single Chip Microcomputer


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.


Keywords:MCU Reference address:A Brief Discussion on the Software Reset Method of Single Chip Microcomputer

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

Design of single chip microcomputer in intelligent alarm system
  The system uses the 16-bit single-chip microcomputer SPCE061A of Lingyang Company as the main controller. The smoke sensor and the human body pyroelectric infrared sensor respectively sense the smoke and human infrared signals, and the single-chip microcomputer makes an alarm action. Two Lingyang single-chip microco
[Microcontroller]
Design of single chip microcomputer in intelligent alarm system
Design of LED dot matrix display system based on STC89C55RD+ single chip microcomputer
Abstract: Based on the in-application programmable function of STC89C55RD+ microcontroller, an LED dot matrix display system is designed. The system is constructed with a master-slave computer structure. The master computer PC can control the display content of the slave computer LED dot matrix system through a seri
[Home Electronics]
Design of LED dot matrix display system based on STC89C55RD+ single chip microcomputer
Research on CortexM3 exception handling of microcontroller core CortexM3 based on ARMv7M
CortexM3 is ARM's first microcontroller core based on ARMv7M. It is very different from ARM7 in terms of instruction execution, exception control, clock management, trace debugging and storage protection. In particular, there are great improvements in the exception handling mechanism, and its exception response only t
[Microcontroller]
Research on CortexM3 exception handling of microcontroller core CortexM3 based on ARMv7M
MCU (51) Switch controls LED on and off
#include regx51.h  sbit LED1=P1^0; //define pin  sbit LED2=P1^1;  sbit key1=P0^0;  sbit key2=P0^1; void delay(unsigned int i){ while(i--); }//Set delay function void main(){     while(1){         LED1=key1; //When the switch is pressed, the electric frequency trigger is low level, and when the switch is released, the
[Microcontroller]
What factors should be considered when choosing an automotive MCU?
  In automotive applications, microcontrollers ( MCUs ) provide critical performance. With the reduction of prices and the increase of consolidation, MCUs are gradually becoming commercialized. However, there are still great differences between different MCUs, so it is particularly important to choose the right automot
[Microcontroller]
What factors should be considered when choosing an automotive MCU?
The working principle of microcontroller MSC1210 and the software and hardware design of CSR power control system
introduction MSC1210 is a highly integrated mixed-signal processing device produced by Texas Instruments (TI) in the United States. It integrates an enhanced 8051 core, 8-channel 24-bit high-precision delta-sigma A/D conversion, 21 interrupt sources, 16-bit PWM, full-duplex UART (and compatible with SPI function), 32K
[Microcontroller]
The working principle of microcontroller MSC1210 and the software and hardware design of CSR power control system
Msp430 microcontroller flashing light program
/**************************************************************************                          Flashing light program *************************************************************************/ #include msp430g2553.h /**************************************** msp430G2553 controls the flashing of two LEDs conn
[Microcontroller]
GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
Beijing, China (November 12, 2024) - GigaDevice, an industry-leading semiconductor device supplier, held a new product launch conference in Shanghai today with the theme of "Yongyue·Core Journey". Industry partners from the fields of industry and digital energy gathered together to celebrate the event. At th
[Industrial Control]
GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号