How does a microcontroller work?

Publisher:BlissfulHikerLatest update time:2013-04-11 Source: 21icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

We have a general understanding of the structure and characteristics of the microcontroller. Next, we will mainly explain how the microcontroller works and what working methods it has.

The microcontroller has four working modes: reset, program execution, low power consumption, and programming and encryption, which are introduced below.

1. Reset method

(1) Why reset?

As we all know, when a single-chip microcomputer executes a program, it always starts from address 0000H, so the CPU must be reset when entering the system, which is also called initialization; in addition, when the system is in a deadlock state due to errors in program execution or operational errors, in order to get rid of this state, it also needs to be reset, just like a computer needs to be restarted when it crashes.

(2) Principle of Reset

The method of resetting the microcontroller is actually very simple. Just add a high level on the RST pin (pin 9) that lasts for 24 oscillation cycles (that is, two machine cycles). If the crystal oscillator is 12M, calculate how long this continuous pulse takes?

(3) How to reset

There are three reset operations: power-on automatic reset, button reset and external pulse reset. Power-on automatic reset is achieved by charging the capacitor of the external reset circuit. When the power is just turned on, the capacitor C starts to charge the pull-down resistor. Since the voltage on both sides of the capacitor cannot change suddenly, the RTS terminal maintains a high level. As long as the charging time does not exceed 1ms, the automatic power-on reset of the microcontroller can be achieved, that is, the system initialization is completed when the power is turned on. In actual engineering applications, if there are no special requirements, this reset method is generally used; the button reset circuit is shown in Figure 2, which is actually based on the power-on reset with R2 and SA added. This circuit is generally used in systems that need to be reset frequently; the external pulse reset circuit is shown in Figure 3. External reset is usually used in systems with higher requirements, such as hoping that the system can be automatically reset after deadlock. External reset is realized by a special integrated circuit, which is commonly known as the "watchdog" circuit. There are many such circuits. They can not only complete the automatic reset function of the microcontroller, but also manage power supply and be used as external memory. For example, X25045, MAX813L, etc. are commonly used chips of this type.

Now let's take a look at what changes will happen inside the microcontroller after it is reset? See the table below:

1.jpg

(4) Status after reset

This is the state of the internal system after the microcontroller is reset. [page]

2. Program execution method

Program execution is the basic working mode of the microcontroller. Since PC=0000 after reset, the program starts executing from address 0000H. At this time, the microcontroller completes a series of operation controls according to the requirements of the instructions, such as making the LED light flash as mentioned earlier. However, in actual use, the program does not start executing from 0000H, but always arranges a jump instruction, such as LJMP START. Why is it arranged like this? We will explain it when we talk about interrupts.

3. Low power operation mode

In a battery-powered system, sometimes in order to reduce battery power consumption, a low-power mode is used when the program is not running. There are two low-power modes: standby mode and power-off mode.

The low power mode is controlled by the power control register PCON (mentioned in the previous lesson). The power control register is an 8-bit register defined bit by bit, and its format is as follows:

Among them: SMOD is the baud rate multiplication bit, used in serial communication; GF1 is the general flag bit 1; GF0 is the general flag bit 0; PD is the power-down mode bit, PD=1, enter the power-down mode; IDL is the standby mode bit, IDL=1, enter the standby mode. In other words, as long as an instruction is executed to make the PD bit or IDL bit 1, it will be fine. So how does the microcontroller enter or exit the power-down working mode and standby working mode.

1. Standby mode

2. Enter standby mode

When the instruction is used to make the IDL of the PCON register = 1, it enters the standby mode. At this time, the CPU stops working, but the clock signal is still provided to the RAM, timer, interrupt system and serial port; at the same time, the stack pointer SP, program counter PC, program status word PSW, accumulator ACC and all general registers are frozen; the current consumption of the microcontroller is reduced from 24mA to 3.7mA, which can save power consumption.

② Exit standby mode

To exit the standby mode, you can introduce an interrupt and place a RETI instruction in the interrupt program. We don't know what an interrupt is yet, but it doesn't matter. In fact, the standby mode is similar to the sleep mode when we use the computer.

(2) Power-off mode

①Enter standby mode

When the instruction is used to make the PD of the PCON register = 1, the power-down mode is entered. At this time, all operations of the microcontroller stop, and only the data in the internal RAM is retained; in the power-down mode, the power supply can be reduced to 2V, and the power consumption is only 50uA. At this time, it is equivalent to turning off the display and hard disk.

② Exit standby mode

The only way to exit the power-down mode is to reset, but the reset should be performed after the power supply voltage returns to normal. The reset time should be greater than 10mS. Before entering the power-down mode, the power supply voltage cannot be reduced. Therefore, a reliable microcontroller circuit should preferably have a power detection circuit. Obviously, the power-down mode and the standby mode are two different low-power modes. The former can reduce power consumption when there is no external event trigger, while the latter is used only when the program stops running. This is a brief introduction to the low-power mode of the microcontroller. More detailed content will be left for the next volume, because that is the work of the experts.

4. Programming and encryption methods

The programming and encryption of the microcontroller are completed by a special device, which is called a programmer or burner. There are many similar products with different functions. The XL2000 on this site is a product that integrates burning, testing, programming and simulation.

Keywords:MCU Reference address:How does a microcontroller work?

Previous article:How to improve your programming skills
Next article:Assembly language and assembly process

Recommended ReadingLatest update time:2024-11-16 19:39

Application of SCA100t and MCU in digital inclination sensor
The digital inclination sensor composed of SCA100t dual-axis inclination sensor and C8051F series single chip produced by VTI company is reliable and has high measurement accuracy. The paper mainly discusses the hardware circuit design and software workflow of the system, analyzes the factors affecting the accuracy,
[Microcontroller]
Application of SCA100t and MCU in digital inclination sensor
Multi-point temperature measurement system based on AVR microcontroller and DS18B20
Introduction to 1DS18B20 and BASCOM-AVR   DS18B20 is a single bus digital temperature sensor produced by DALLAS, USA. Only one port line is needed to read or write information from DS18B20. In single bus working mode, multiple DS18B20 can be connected to one signal line, which is particularly suitable for forming
[Microcontroller]
Multi-point temperature measurement system based on AVR microcontroller and DS18B20
The use of Kalman filter on single chip microcomputer
#ifndef _KALMAN_H_ #define _KALMAN_H_ extern KalmanGain; // Kalman gain extern EstimateCovariance; // Estimated covariance extern MeasureCovariance; // Measured covariance extern EstimateValue; // Estimated value extern void KalmanFilterInit(void); extern KalmanFilter( Measure); #endif  
[Microcontroller]
The use of Kalman filter on single chip microcomputer
Program to light a lamp based on the minimum system of 51 microcontroller
51 microcontroller minimum system Today we start to learn about 51 microcontroller programming. First, we need to understand the basic conditions required for the microcontroller to work. In the previous content, we know that the pins of the 51 microcontroller include power pins, clock pins, control pins, and general-
[Microcontroller]
Program to light a lamp based on the minimum system of 51 microcontroller
What does a nop in a 51 MCU mean?
The standard 51 is 12T, which means 12 clock cycles (crystal oscillator cycle, for example, 12M, the cycle is 1/12M, unit is second), the machine does an instruction cycle, exactly 1/12M*12=1uS, common instructions such as nop is one cycle, exactly 1uS, most of the others are more than one cycle, multiplication and di
[Microcontroller]
51 MCU serial port control relay
There is a project in the laboratory that uses the alarm function. For example, when the temperature or stress is too high or too low, the alarm is activated, and a command is sent to the serial port to control the relay. Unfortunately, I connected the positive and negative poles in reverse last year and it burned. Re
[Microcontroller]
Microcontroller literacy: the relationship between MCS51 and 8051/8031, etc.
We always talk about 8051, 8031, and now there is 89C51 and 89s51. What is the relationship between them? MCS51 refers to the general name of a series of single- chip microcomputers produced by the American INTEL company (yes, the famous INTEL) . This series of single-chip microcomputers includes many varieties, su
[Power Management]
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号