The 8051 microcontroller has a total of 21 special registers. Some of them are briefly introduced as follows:
Program Counter (PC). In the training, we already know that PC is a 16-bit counter, and its function is to control the execution order of the program. Its content is the address of the instruction to be executed, and the addressing range is up to 64KB. PC has the function of automatically adding 1, so as to realize the sequential execution of the program. PC has no address and is not addressable, so the user cannot read and write it, but can change its content through instructions such as transfer, call, return, etc. to realize the transfer of the program. Because the address is not within the SFR (special register), it is generally not counted as a special register.
Accumulator (ACC). The accumulator is an 8-bit register, the most commonly used special register, with many functions and an important position. It can be used to store operands as well as intermediate results of operations. The operands of most single-operand instructions in the MCS-51 microcontroller are taken from the accumulator, and one of the operands in many double-operand instructions is also taken from the accumulator.
B register. B register is an 8-bit register, mainly used for multiplication and division operations. In multiplication operation, B stores the multiplier. After the multiplication operation, the upper 8 bits of the product are stored in B. In division operation, B stores the divisor. After the division operation, the remainder is stored in B. In addition, B register can also be used as a general data register.
Program Status Word (PSW). The program status word is an 8-bit register used to store various status information during program execution. The status of some bits is automatically set by hardware based on the program execution results, while the status of some bits is set using software methods. The bit status of PSW can be tested using special instructions or read out using instructions. Some conditional transfer instructions will perform program transfers based on the status of some bits of PSW. The definitions of each bit of PSW are as follows:
Except for PSW.1, which is reserved and unused, the definitions and uses of the remaining bits are as follows:
CY (PSW.7) - Carry flag. CY is the most commonly used flag in PSW. It has two functions: one is to store the carry flag of arithmetic operations. When performing addition or subtraction operations, if the highest bit of the operation result has a carry or borrow, CY is set to "1" by hardware, otherwise it is cleared to "0"; the other is to be used as an accumulation bit in bit operations. In bit transfer, bit AND, bit OR, etc. operations, one of the operation bits is fixed to be the carry flag.
AC (PSW.6) - Auxiliary carry flag. In addition and subtraction operations, when the lower 4 bits carry or borrow to the upper 4 bits, AC is set to "1" by hardware, otherwise the AC bit is cleared to "0". The AC bit status is also used in BCD code adjustment.
F0 (PSW.5) - User flag. This is a user-defined flag that needs to be set or reset by software to control the direction of the program.
RS1 and RS0 (PSW.4, PSW.3) - register bank selection bits. They are used to select the general register bank currently used by the CPU. There are 4 groups of general registers, and their corresponding relationships are as follows:
00: 0 group 01: 1 group 10: 2 groups 11: 3 groups
The status of these two selection bits is set by software, and the selected register group is the current general register group. However, when the microcontroller is powered on or reset, RS1 RS0 = 00.
OV (PSW.2) - Overflow flag. In signed addition and subtraction operations, OV = 1 means that the addition and subtraction operations exceed the valid range of signed numbers that can be represented by accumulator A (-128 ~ +127), that is, an overflow occurs, so the operation result is wrong. Otherwise, OV = 0 means that the operation is correct, that is, no overflow occurs.
P (PSW.0) - Parity flag. Indicates the parity of the content in accumulator A. If there are an odd number of "1"s in A, P is set to "1", otherwise it is set to "0". Any instruction that changes the content in accumulator A will affect the P flag. This flag is of great significance to data transmission in serial communication. In serial communication, parity check is often used to check the reliability of data transmission.
Data pointer (DPTR). The data pointer is a 16-bit register. When programming, DPTR can be used as a 16-bit register or as two 8-bit registers, namely: DPH DPTR high byte, DPL DPTR low byte. DPTR is usually used as an address pointer when accessing external data memory. Since the addressing range of external data memory is 64 KB, DPTR is designed to be 16 bits.
Stack pointer (SP—StackPointer). The stack is a special storage area used to temporarily store data and addresses. It accesses data according to the principle of "first in, last out". There are two operations on the stack: push and pop. Since the stack of the MCS-51 microcontroller is located in the internal RAM, SP is an 8-bit register. After the system is reset, the content of SP is 07H, so the stack actually starts from unit 08H after reset. However, units 08H to 1FH belong to working register areas 1 to 3 respectively. If the program needs to use these areas, it is best to change the SP value to 1FH or a larger value.
The following points are made on the byte addressing problem of special registers:
(1) The 21 byte-addressable special registers are scattered discontinuously in the upper 128 units of the internal RAM. Although there are many free addresses, they cannot be used by the user.
(2) The program counter PC does not occupy a RAM unit. It is physically independent and therefore a non-addressable register.
(3) Only direct addressing can be used for special registers. When writing, you can use either register symbols or registers.
Previous article:8051 MCU Tutorial Lesson 10: Data Transfer Instructions
Next article:Differences between STC89C51 and AT89S51
- Popular Resources
- Popular amplifiers
- 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
- The concepts and differences between TTL level, CMOS level and RS232 communication level
- How to trigger ADC of C2000 series TMS320F28335?
- Measured broadband output noise of 0.8uVrms ultra-low noise regulator LT3045
- [RVB2601 Creative Application Development] Zero-based Part 2: Play with RVB2601 (based on RISC-V MCU) HelloWorld
- [Review of Arteli Development Board AT32F421] + Final Chapter: Connect the dots and solve projects
- 42 lights version of love (heart-shaped) water lamp, the romance of science and engineering men, the magic tool for chasing girls, directly on the information
- It's a power supply problem. Can anyone help me solve it?
- Principle of MCU key debounce
- Solutions to common IAR errors
- Some information about microcontroller controlling buzzer to play music