8051 MCU - Software Reset

Publisher:breakthrough2Latest update time:2024-07-30 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

ISP_CONTR: ISP/IAP control register

D7

D6

D5

D4

D3

D2

D1

D0

Reset value

ISPEN

SWBS

SWRST

-

-

WT2

WT1

WT0

000x,0000

  • SWBS: When set to 0, the software will start from the user application area after reset; when set to 1, the software will start from the ISP program area after reset. This can only be achieved by working directly with SWRST.

  • SWRST: When set to 0, no software reset is performed; when set to 1, a software system reset is generated and the hardware is automatically cleared.

This reset resets the entire system. All special function registers will be reset to their initial values ​​and the I/O ports will also be initialized.

[Example] Use a key interrupt to reset the MCU software. After the reset, the LED light flashes for a while, and then the MCU maintains the current state and idles. If you want to continue flashing the LED, you need to reset the MCU.

Software reset code:

1 #include "stc.h"

2

3 #define LED_PORT P2 //Define LED control port as P2

4

5/************************************************

6 *Function name: Delay

7 * Input: None

8 *Output: None

9 *Description: Delay for a period of time

10************************************************/

11 void Delay(void)

12 {

13 unsigned char i,j;

14

15 for(i=0;i<130;i++)

16 for(j=0;j<255;j++);

17 }

18 /************************************************

19 *Function name:SoftReset

20 * Input: None

21 *Output: None

22 * Description: Software reset MCU

twenty three ********************************************/

24 void SoftReset(void)

25 {

26 ISP_CONTR=0x20;

27 }

28 /************************************************

29 *Function name:EXTInit

30 *Input: None

31 *Output: None

32 * Description: External interrupt initialization

33************************************************/

34 void EXTInit(void)

35 {

36 EX1=1; //Enable external interrupt 1

37 IT1=0; //Low level trigger

38 EA=1; //Enable all interrupts

39 }

40 /************************************************

41 *Function name: main

42 * Input: None

43 *Output: None

44 *Description: Function

45************************************************/

46 void main(void)

47 {

48 unsigned char i;

49

50 EXTInit(); //External interrupt initialization

51

52 for(i=0;i<20;i++) //Loop flashing LED light

53 {

54 LED_PORT=~LED_PORT;

55 Delay();

56 }

57

58 while(1)

59 {

60; //No operation

61 }

62 }

63 /************************************************

64 *Function name: EXT1IRQ

65 *Input: None

66 *Output: None

67 * Description: External interrupt 1 interrupt service function reset operation

68 ********************************************/

69 void EXT1IRQ(void)interrupt 2

70 {

71 SoftReset();

72 }

73


Code Analysis:

SoftReset is a reset operation function, which assigns the value of 0x20 to the ISP/IAP control register ISP_CONTR, that is, sets "SWRST" in ISP_CONTR to 1 to perform a software reset. It should be noted that the software reset here is a real reset, which has the same effect as a hardware reset.

In the main function, after initializing the external interrupt, the LED light flashes for a while, and then enters the while(1) infinite loop to perform no operations.

The software reset operation is placed in the external interrupt 1 interrupt service function. As long as the external interrupt 1 is triggered, the microcontroller will be reset.


Reference address:8051 MCU - Software Reset

Previous article:Simulate software reset
Next article:8051 MCU - interrupt wakeup

Recommended ReadingLatest update time:2024-11-16 09:47

Understanding automotive control chips (MCU) in one article
This article introduces MCU chips in the four domains of body, chassis, power, and cockpit from four dimensions: work requirements, performance requirements, industrial structure, and industry barriers . It also summarizes the application status of domestic MCU chips for reference by practitioners.
[Automotive Electronics]
Understanding automotive control chips (MCU) in one article
Design of intelligent lighting controller for highway tunnel based on LPC2119 microcontroller design
introduction Tunnels are an important part of highways, and tunnel lighting systems are an essential guarantee for vehicles to safely enter, pass, and leave tunnel areas. At present, the lighting of long tunnels is divided into entrance section, transition section, basic section and exit section. The lighting fixtures
[Microcontroller]
Design of intelligent lighting controller for highway tunnel based on LPC2119 microcontroller design
51 single chip microcomputer output square wave problem
1. NOTE Today I will share a topic about the problem of 51 single-chip microcomputer outputting square waves. Okay, let's get to the point. 2. Title It is known that the clock frequency of the 8051 microcontroller is 6MHZ. Through the working mode 1 of timer 1, a 1KHZ rectangular wave with a duty cycle of 60% is out
[Microcontroller]
51 single chip microcomputer output square wave problem
nRF24L01p+AVR MCU ATmage88 RF transceiver program
The microcontroller source program is as follows: #define _nRF24L01_C_ #include "nRF24L01.h" INT8U CE_Status = 0; /* ================================================================================ Function : L01_GetCEStatus( ) Description : Get the status of the CE PIN Input : NONE Output: 1:CE=1, 0:CE=0 =========
[Microcontroller]
STC15 series MCU SPI usage tutorial (I)
1. Hardware Wiring 1. Ordinary SPI device wiring For example, NRF24L01 can be directly connected to IO 2. FLASH device wiring For example, GD25Q80BSIG needs to add a pull-up resistor 2. Programming 1. Registers related to SPI ① SPCTL register ② SPSTAT register ③ SPDAT register ④ AUXR1/P_SW1 register 2
[Microcontroller]
STC15 series MCU SPI usage tutorial (I)
Key.h header file download - 4*4 keypad driver header file for AVR series microcontrollers
/*****************************************************************************       File name: Key.h       File ID: _KEY_H_       Abstract: 4*4 keypad driver header file for AVR series microcontrollers       Current version: V1.0 *****************************************************************************/ #ifnd
[Microcontroller]
The processing of local variables in functions in the MCU compiler is different from that of PC
Usually we all learn the standard C language tutorial before engaging in the programming of C language for microcontrollers. Then we must first understand that the standard C language is actually a language that originated on the PC platform, and the standard C language will certainly not take into account the particu
[Microcontroller]
Interface Program between PCF8591 and AT89C51 MCU
  AT89C51 is used as the main device. Four PCF8591 chips are connected to the I2C bus. The chip addresses are (OOOb, OlOb, 020b, 400b) respectively. P3.6 of 89C51 is used as the SCL signal. P3.7 is used as the SDA signal. The analog input of each chip is input in single-ended mode. The reference voltage VREF is 4.8V.
[Microcontroller]
Interface Program between PCF8591 and AT89C51 MCU
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号