We know that the microcontroller has ROM, RAM, and parallel I/O ports. So, apart from these things, what else is inside the microcontroller? How are these bits and pieces connected together? Let's make a complete analysis of the inside of the microcontroller!
Look at Figure (1) (This figure is too large, please find a book to look at it. Any book about single-chip microcomputers will have it). From the figure, we can see that there is a CPU inside the 51 single-chip microcomputer for calculation and control, four parallel I/O ports, namely P0, P1, P2, and P3, ROM for storing programs, RAM for storing intermediate results, and a timer/counter, serial I/O port, interrupt system, and an internal clock circuit. There are so many things inside a 51 single-chip microcomputer.
Further analysis of the above diagram shows that to read and write parallel I/O ports, we only need to send data to the latch of the corresponding I/O port. So how do we use timers/counters, serial I/O ports, etc.? In the microcontroller, there are some independent storage units used to control these devices, which are called special function registers (SFRs). In fact, we have already come across the special function register P1. What else are there? See Table 1
Table 1
Next, we introduce several commonly used SFRs, see Figure 2.
Figure 2[page]
ACC: Accumulator, usually represented by A. You can't understand what it is from the name. It is a register, not a thing for adding. Why is it given such a name? Perhaps it is because one of the numbers must be in ACC when the arithmetic unit performs calculations. Its name is special and its identity is also special. Later we will learn about instructions and find that all calculation instructions are inseparable from it.
2. B: A register. It is used to store the multiplier or divisor when doing multiplication or division. It can be used as you wish when not doing multiplication or division.
3. PSW: Program Status Word. This is a very important thing. It contains many states of the CPU when it is working. Through this, we can understand the current state of the CPU and make corresponding processing. Please refer to Table 2 for its functions.
Table 2
Below we will introduce each of your uses one by one
(1) CY: Carry flag. The arithmetic unit in 8051 is an 8-bit arithmetic unit. As we know, an 8-bit arithmetic unit can only represent 0-255. If we add two numbers, the sum of the two numbers may exceed 255, so the highest bit will be lost, causing an operation error. What should we do? The highest bit is carried here. This way, everything is fine.
Example: 78H+97H (01111000+10010111)
(2) AC: Half carry flag.
Example: 57H+3AH (01010111+00111010)
(3) F0: User flag. We (programmers) decide when to use it and when not to use it.
(4) RS1, RS0: Working register bank selection bits. We already know this.
(5) 0V: Overflow flag. We will talk about overflow later.
(6) P: Parity bit: It is used to indicate the parity of the number of binary digits "1" in the ALU operation result. If it is an odd number, P = 1, otherwise it is 0.
Example: The result of a certain operation is 78H (01111000). Obviously, the number of 1s is an even number, so P=0.
4. DPTR (DPH, DPL): Data pointer, which can be used to access any unit in the external data memory. If not used, it can also be used as a general register. We can decide how to use it.
5. P0, P1, P2, P3: As we already know, these are the registers of four parallel input/output ports. The contents in them correspond to the output of the pins.
6. SP: stack pointer.
Introduction to stacking: In daily life, we have all noticed this phenomenon: the dishes at home are stacked one by one, the latest one is placed on the top, and the earliest one is placed at the bottom. When taking things out, it is just the opposite, taking things from the top first. We can summarize this phenomenon in one sentence: "First in, last out, last in, first out". Please think about it, where else can we find this phenomenon? In fact, it can be found everywhere, such as the bricks and materials piled up on the construction site, and the goods in the warehouse, which are all "first in, last out, last in, first out". This is actually a rule for storing and retrieving items, which we call "stack".
In a single-chip microcomputer, we can also construct such an area in RAM to store data. The rule for storing data in this area is "first in, last out, last in, first out", which we call a "stack". Why do we need to store data in this way? Can't the memory itself store data by address? Yes, knowing the address does allow us to know the content inside, but if we need to store a batch of data, wouldn't it be troublesome to know the address of each data? If we place the data one by one, then we only need to know the address unit of the first data (see Figure 2). If the first data is at 27H, then the second and third will be at 28H and 29H. Therefore, using a stack as a method to store data can simplify operations.
So where is the stack in 51? The area that can store data in the microcontroller is limited. We cannot allocate a place for the stack, so we open up a place in the memory (RAM) for the stack, but which part of the memory should be used? It is still difficult to determine, because 51 is a general-purpose microcontroller, and the actual needs of each person are different. Some people need more stacks, while others do not need so much, so no matter how to allocate it, it is not appropriate. How to solve this problem? If it is not easy to divide it, just don't divide it. Give the right to divide it to the user (programmer) and decide it according to their own needs. Therefore, the position of the stack in the 51 microcontroller can be changed. And this change is reflected in the change of the value in SP. Look at Figure 2. The value in SP is equal to 27H, isn't it equivalent to a pointer pointing to the 27H unit? Of course, in the real 51 machine, the position pointed to by the pointer at the beginning is not the location where the data is stored, but the previous location where the data is stored. For example, if the pointer points to the 27H unit at the beginning, then the location of the first data is the 28H unit, not the 27H unit. Why is this the case? We will explain it when we learn the stack command.
Previous article:Timing Analysis of MCU
Next article:STC series MCU development matters needing attention
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
- A precision rectification experiment
- Video: Talking about TI CC2650
- How stable is RT-Thread?
- TI - MCU - MSP430 User Guide 2 -> CPU/CPUX
- How to improve the hardware and software architecture of embedded minimum systems?
- Among domestic chips, which ones are suitable for smart homes?
- What's the problem with WeChat voice echo? Is it a network problem, a setting problem, or a device problem?
- STM32CubeMX is driving me crazy, experts please help!
- Implementation of Ethernet communication between TI C6678 DSP and PC
- Method for programming the on-chip flash of LPC2000 series microcontrollers