Detailed explanation of the basics of 8051 microcontroller special function registers SFR

Publisher:WhisperingGlowLatest update time:2021-04-23 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Reference address:Detailed explanation of the basics of 8051 microcontroller special function registers SFR

Previous article:8051 MCU Tutorial Lesson 10: Data Transfer Instructions
Next article:Differences between STC89C51 and AT89S51

Latest Microcontroller Articles
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号