This article mainly talks about the memory mapping of the RAM part of the 51 microcontroller. Its memory space is as shown in the figure below:
There are 256 bytes of RAM space inside the 51 microcontroller. The lower 128 bytes are the working register group area (0x00H-0x1FH), bit addressing area (0x02H-0x2FH), general RAM area (0x30H-0x70H), and SFR register area. (0x80-0xFF) This space defines all control registers and status registers of the 51 microcontroller. Next, we will introduce the functions and access methods of each area one by one in the bottom-up order in the above figure.
working register area
The working register area is R0-R7, each of which is 1 byte, but the 51 microcontroller has a total of 4 sets of working registers, and the microcontroller can only have one set of working registers during operation. The addresses of each working register and the selection of working register groups are shown in the figure below:
The function of the working register is to pass function parameters, assign values to local variables, save the results of function execution, etc. In addition, many instructions also use working registers. We can first think about this question: Can the sum of four numbers be realized using a 51 microcontroller? Let’s take a look at the picture below:
The add function receives three parameters a, b, c but no d. Can the parameter d not be passed? Let’s first take a look at the explanation from the official documentation:
Cx51编译器最多在MCU寄存器中传递三个函数参数。由于不将参数写入内存或从内存读取参数,因此该机制显著提高了系统性能。参数或参数传递可以由REGPARMS和NOREGPARMS指令控制:
It turns out that 51 can only pass up to three parameters, but what should I do if it exceeds three now? Can we only add and subtract three numbers? As shown in the figure below, the parameters passed by the add function are 1, 2, 3, and 4 respectively. The result of our operation is A, which is 10 in decimal. So where does the fourth parameter go?
After simulation, we know that the fourth parameter is pushed onto the stack. (It seems that the stack can be in the working register area, but it is best not to do this. Instead, you should let SP point to after 0x60 in the .S file)
Note: The int in the 51 microcontroller is 2 bytes! The default value of the 51 microcontroller SP when powered on is 0x07, i, j, and t are pushed into the stack 0x07+2*3=0x13. The 51 microcontroller stack is growing positively, so the position of the fourth parameter is where 0x14 and 0x15 are.
2. Bit addressing area
0x20-0x2F has a total of 16 bytes and 128 bits, so the addressing range is 0-0x7F. The memory mapping relationship is as shown in the figure below:
The usage method is the keyword unique to C51, and the assembly instruction corresponding to the sbit keyword is BIT. (Note: SFR registers can also be bit addressable!)
The modified keyword sbit points to the location of P2.1. P2^1 is bit-addressed in the SFR register area. The reason why it is 1 is because it has not been assigned a value, so its default value is 1. The bit addressing area is very useful. For example, bit operations on P2.1 will not affect other I/O ports such as P2.0 and P2.2, so it is a very convenient operation method. In fact, STM32 can also achieve this effect!
3. General RAM area
The general RAM area can run the local variables of the function, because the SP pointer protects the calling function and the interrupt function site. The specific performance is:
1. Protection breakpoint: Push PC onto the stack, and after executing the interrupt function, pop up the previous value of PC and restore to the point where the program was running before the interruption.
2. Protect the scene: protect the value of the register group.
4. SFR register area
The special function register area defines the control registers and status registers that control and monitor the operation of the 51 microcontroller. Timers, I/O ports, serial ports, interrupts and other related registers are all defined here. At the same time, this area is discrete and is reserved for manufacturers. However, the 52 microcontroller can access it, but it requires indirect addressing. For C language programming, there is no need to pay attention to this. The C language itself can convert it. . Then, the stack of the 52 microcontroller has grown by 128 bytes for us to use.
Okay, let’s review and summarize the above content!
The whole article mainly introduces the functions of each module in the RAM area of 51 microcontroller through KEIL and programs. The first aspect is the address space occupied by the general register group and the role of this area when the program is running. Secondly, the importance and role of the bit addressing area. If bit addressing is not used, the read-write-modify form can only be used. This is not only inconvenient to use, but also increases the amount of code. The third aspect is the importance of general RAM area and SFR area.
Previous article:Memory mapping of 51 microcontroller (2)
Next article:Summary of 51 microcontroller knowledge points
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- [Share] Good learning materials - Introduction to electrostatics
- [Summary of the shortlist] GigaDevice GD32L233 review event
- About Ingenic IP5328P
- Practical Power Management for Embedded Media Engines
- (Bonus 11) GD32L233 Review - PWM Driven Active Buzzer
- Several issues worth noting in DSP development
- [Silicon Labs BG22-EK4108A Bluetooth Development Review] 1. Unboxing
- Why is the output ripple of the circuit I designed so large?
- COCOFLY Tutorial - Crazy Shell Drone Series Quick Start [3] OPENMV Script Burning
- [Telink's new generation of low-power, high-performance, multi-protocol wireless kit B91 review] HomeAssistant+B91zigbee network access