So you may have guessed something from the name itself – “Special Function Registers” known with an acronym SFR. Well, your guess is right 🙂 Okay! Lets come to the point. There are 21 Special function registers (SFR) in 8051 micro controller and this includes Register A, Register B, Processor Status Word (PSW), PCON etc etc. There are 21 unique locations for these 21 special function registers and each of these register is of 1 byte size. Some of these special function registers are bit addressable (which means you can access 8 individual bits inside a single byte), while some others are only byte addressable. Let’s take a look at them in detail.
The most important of all special function registers, that’s the first comment about Accumulator which is also known as ACC or A. The Accumulator (sometimes referred to as Register A also) holds the result of most of arithmetic and logic operations. ACC is usually accessed by direct addressing and its physical address is E0H. Accumulator is both byte and bit addressable. You can understand this from the figure shown below. To access the first bit (i.e bit 0) or to access accumulator as a single byte (all 8 bits at once), you may use the same physical address E0H. Now if you want to access the second bit (i.e bit 1), you may use E1H and for third bit E2H and so on.
The major purpose of this register is in executing multiplication and division. The 8051 micro controller has a single instruction for multiplication (MUL) and division (DIV). If you are familiar with 8085, you may now know that multiplication is repeated addition, where as division is repeated subtraction. While programming 8085, you may have written a loop to execute repeated addition/subtraction to perform multiplication and division. Now here in 8051 you can do this with a single instruction.
Ex: MUL A,B – When this instruction is executed, data inside A and data inside B is multiplied and answer is stored in A.
Note: For MUL and DIV instructions, it is necessary that the two operands must be in A and B.
Note: Follow this link if you are interested in knowing about differences between a microprocessor and microcontroller.
Register B is also byte addressable and bit addressable. To access bit o or to access all 8 bits (as a single byte), physical address F0 is used. To access bit 1 you may use F1 and so on. Please take a look at the picture below.
Note: Register B can also be used for other general purpose operations.
As you may already know, there are 4 ports for 8051. If you are unfamiliar of the architecture of 8051 please read the following article:- The architecture of 8051
So 4 Input/Output ports named P0, P1, P2 and P3 has got four corresponding port registers with same name P0, P1, P2 and P3. Data must be written into port registers first to send it out to any other external device through ports. Similarly any data received through ports must be read from port registers for performing any operation. All 4 port registers are bit as well as byte addressable. Take a look at the figure below for a better understanding of port registers.
From the figure:-
- The physical address of port 0 is 80
- The physical address of port 1 is 90
- And that of port 2 is A0
- And that of port 3 is B0
Known popularly with an acronym SP, stack pointer represents a pointer to the the system stack. Stack pointer is an 8 bit register, the direct address of SP is 81H and it is only byte addressable, which means you cant access individual bits of stack pointer. The content of the stack pointer points to the last stored location of system stack. To store something new in system stack, the SP must be incremented by 1 first and then execute the “store” command. Usually after a system reset SP is initialized as 07H and data can be stored to stack from 08H onwards. This is usually a default case and programmer can alter values of SP to suit his needs.
Power Management Register (PCON)
Power management using a microcontroller is something you see every day in mobile phones. Haven’t you noticed and got wondered by a mobile phone automatically going into stand by mode when not used for a couple of seconds or minutes ? This is achieved by power management feature of the controller used inside that phone.
As the name indicates, this register is used for efficient power management of 8051 micro controller. Commonly referred to as PCON register, this is a dedicated SFR for power management alone. From the figure below you can observe that there are 2 modes for this register :- Idle mode and Power down mode.
Setting bit 0 will move the micro controller to Idle mode and Setting bit 1 will move the micro controller to Power down mode.
Processor Status Word (PSW)
Commonly known as the PSW register, this is a vital SFR in the functioning of micro controller. This register reflects the status of the operation that is being carried out in the processor. The picture below shows PSW register and the way register banks are selected using PSW register bits – RS1 and RS0. PSW register is both bit and byte addressable. The physical address of PSW starts from D0H. The individual bits are then accessed using D1, D2 … D7. The various individual bits are explained below.
|0||P||D0||Parity||This bit will be set if ACC has odd number of 1’s after an operation. If not, bit will remain cleared.|
|1||–||D1||User definable bit|
|2||OV||D2||Overflow||OV flag is set if there is a carry from bit 6 but not from bit 7 of an Arithmetic operation. It’s also set if there is a carry from bit 7 (but not from bit 6) of Acc|
|3||RS0||D3||Register Bank select bit 0||LSB of the register bank select bit. Look for explanation below this table.|
|4||RS1||D4||Register Bank select bit 1||MSB of the register bank select bits.|
|5||F0||D5||Flag 0||User defined flag|
|6||AC||D6||Auxiliary carry||This bit is set if data is coming out from bit 3 to bit 4 of Acc during an Arithmetic operation.|
|7||CY||D7||Carry||Is set if data is coming out of bit 7 of Acc during an Arithmetic operation.|
At a time registers can take value from R0,R1…to R7. You may already know there are 32 such registers. So how you access 32 registers with just 8 variables to address registers? Here comes the use of register banks. There are 4 register banks named 0,1,2 and 3. Each bank has 8 registers named from R0 to R7. At a time only one register bank can be selected. Selection of register bank is made possible through PSW register bits PSW.3 and PSW.4, named as RS0 and RS1.These two bits are known as register bank select bits as they are used to select register banks. The picture will talk more about selecting register banks.
So far we have discussed about all major SFR’s in 8051. There many other still waiting! Please remember there are 21 SFR’s and we have discussed only 9 specifically. The table below lists all other 12 SFR’s.
|DPH||83||Data pointer registers (High). Only byte addressing possible.|
|DPL||82||Data pointer register (Low). Only byte addressing possible.|
|IP||B8||Interrupt priority. Both bit addressing and byte addressing possible.|
|IE||A8||Interrupt enable. Both bit addressing and byte addressing possible.|
|SBUF||99||Serial Input/Output buffer. Only byte addressing is possible.|
|SCON||98||Serial communication control. Both bit addressing and byte addressing possible.|
|TCON||88||Timer control. Both bit addressing and byte addressing possible.|
|TH0||8C||Timer 0 counter (High). Only byte addressing is possible.|
|TL0||8A||Timer 0 counter (Low). Only byte addressing is possible.|
|TH1||8D||Timer 1 counter (High). Only byte addressing is possible.|
|TL1||8B||Timer 1 counter (Low). Only byte addressing is possible.|
|TMOD||89||Timer mode select. Only byte addressing is possible.|