Different Types of Registers used in 8051 Microcontroller - LEKULE

Breaking

25 Aug 2016

Different Types of Registers used in 8051 Microcontroller

Register is a main part in the microcontrollers and processors that provide a fast way to collect and store data. If we want to manipulate data with a controller or processor by performing addition, subtraction, and so on, we cannot do that directly in the memory, but it needs registers to process and store the data. Microcontrollers contain several types of registers that can be classified according to their content or instructions that operate in them.

Different Types of Registers in the 8051 Microcontroller


Register

A register is a small place in a CPU that can store small amounts of the data used for performing various operations such as addition and multiplication and loads the resulting data on main memory. Registers contain the address of the memory location where the data is to be stored. The size of the register is very important for modern controllers. For instance, for a 64-bit register, a CPU tries to add two 32-bit numbers and gives a 64-bit result.

Types of Registers

The 8051 microcontroller contains mainly two types of registers:
  • General purpose registers (Byte addressable registers)
  • Special function registers (Bit addressable registers)
8051 RAM Memory
8051 RAM Memory


The 8051 microcontroller consists of 256 bytes of RAM memory, which is divided into two ways, such as 128 bytes for general purpose and 128 bytes for special function registers (SFR) memory. The memory which is used for general purpose is called as RAM memory, and the memory used for SFR contains all the peripheral related registers like Accumulator, ‘B’ register, Timers or Counters, and interrupt related registers.

General Purpose Registers

General Purpose Memory
General Purpose Memory


The general purpose memory is called as the RAM memory of the 8051 microcontroller, which is divided into 3 areas such as banks, bit-addressable area, and scratch-pad area. The banks contain different general purpose registers such as R0-R7, and all such registers are byte-addressable registers that store or remove only 1-byte of data.

Banks and Registers

The B0, B1, B2, and B3 stand for banks and each bank contains eight general purpose registers ranging from ‘R0’ to ‘R7’. All these registers are byte-addressable registers. Data transfer between general purpose registers to general purpose registers is not possible. These banks are selected by the Program Status Word (PSW) register.
General Purpose Registers
General Purpose Registers

PSW (Program Status Word) Register

The PSW register is a bit and byte-addressable register. This register reflects the status of the operation that is carried out in the controller. The PSW register determines bank selection by a RS1 and RS0, as shown below. The physical address of the PSW starts from D0h and the individual bits are accessed with D0h to D7h.

PSW Registers
PSW Registers


Carry Flag (C): The Address of the Carry flag is D7. This carry flag is affected when the bit is generated from the 7th position.
When C=0 carry resets
C=1 carry sets
Carry Flag
Carry Flag


Auxillary Flag(AC): The address of the auxiliary carry is D5. This auxiliary carry is affected when a bit is generated from the 3rd position to the 4th position.
AC=0 auxiliary is reset
AC=1 auxiliary is set
Auxiliary Carry (AC)
Auxiliary Carry (AC)


 Overflow Flag (OV): The address of the overflow flag is D2. When a bit is generated from the 6th position to the 7th position, then the overflow flag is affected.
OV=0 overflow flag resets
OV=1 overflow flag sets
Overflow Flag
Overflow Flag


Parity Flag (P): The address of the parity flag is D0. While performing arithmetic operations, if the result is 1, then the parity flag is set – otherwise reset.


RS1 and RS0

The RS1 and RS0, the bits in PSW register, are used to select different memory location (bank0 to bank4) in the RAM memory.
Bank selection Registers
Bank selection Registers

The following is an example for using this register.

The following example demonstrates addition of two numbers and then the storage of final value in the Bank1 register using assembly level program.

Org 0000h
MOV PSW,#00h
MOV A, 15
ADD A, 20
MOV 00h, A
END


Assembly program to move 6 natural numbers in bank0 register R0-R5
Org 0000h (starting addresses declaration)
MOV PSW, #00h (open the bank0 memory)
MOV r0, #00h (starting address of bank0 memory)
MOV r1, #01h
MOV r2, #02h
MOV r2, #03h
MOV r3, #04h
MOV r4, #05h
END


Assembly program to move 6 natural numbers in bank1 register R0-R7
Org 0000h (starting addresses declaration)
MOV PSW, #08h (open the bank1 memory)
MOV r0, 00h (value send to the bank1 memory)
MOV r1, 02h
MOV r2, 02h
MOV r2, 03h
MOV r3, 04h
MOV r4, 05h
MOV r5, 06h
MOV r6, 07h
MOV r7, 08h
END

Special Function Registers (SFR)


Special function registers are upper RAM memory in the 8051 microcontroller. These registers contain all peripheral related registers like P0, P1, P2, P3, timers or counters, serial port and interrupts-related registers. The SFR memory address starts from 80h to FFh. The SFR register is implemented by bit-address registers and byte-address registers.

 Special Function Registers (SFR)



Special Function Registers (SFR)
The accumulator, B register, Po, P1, P2, P3, IE registers are bit-addressable register remaining all are byte-addressable registers.


Accumulator
The accumulator which is also known as ACC or A is a bit as well as a byte-addressable register by an address of the accumulator. If you want to use a bit-addressable register, you can use a single bit (E0) of register and you can use an 8-bit of the accumulator as a byte-addressable register. The accumulator holds the results of most Arithmetic and logical operations.


Accumulator register
Accumulator register


The Assembly program for subtraction used with an Accumulator
Org 0000h
MOV R0, #09h
MOV A, #03h (1byte data)
SUBB A, 01h (1byte data)
END


B-Register
The B-register is a bit and byte-addressable register. You can access 1-bit or all 8-bits by a physical address F0h. Suppose to access a bit 1, we have to use f1. The B register is only used for multiplication and division operations.
B-Register
B-Register


The Assembly program for multiplication used with a B-Register
Org 0000h
MOV A, #09h
MOV B, #03h
MUL A, B (Final value stored in A)
END
The Assembly program for Division used with a B-Register
Org 0000h
MOV A, #09h
MOV B, #03h
DIC A, B (Final value stored in A)
END


Port Registers
The 8051 microcontroller consists of 4-input and output ports (P0, P1, P2, and P3) or 32-I/O pins. Each pin is designed with a transistor and P registers. The pin configuration is very important for a microcontroller that depends on the logic states of the registers. The pin configuration as input given by 1 or output 0 depends on the logic states. If logic 1 is applied to the bit of the P register, the output transistor switches off the appropriate pin that acts as an input pin.

Port Registers of 8051
Port Registers of 8051


Assembly program to toggle LEDs of Port0
ORG 0000h
RETURN: MOV P0, #00h
ACALL DEL1
MOV P0, #0FF
ACALL DEL1
SJMP RETURN
DEL1: MOV R2, #200
DEL: DJNZ R0, #230
DJNZ R2, DEL
RET
END


Counters and registers
Many microcontrollers consist of one or more timers and counters. The timers are used to generate precious time delay and the source for the timers is crystal oscillator. The counters are used to count the number of external events – for instance, the objective counter , and the source for counters are external pulses applied across the counter pin.

The 8051 microcontroller consists of two 16-bit timers and counters such as timer 0 and timer 1. Both the timers consist of a 16-bit register in which the lower byte is stored in the TL and the higher byte is stored in the TH. The Timer can be used as a counter as well as for timing operation that depends on the source of the clock pulses to the counters.

The Counters and Timers in 8051 microcontroller contain two special function registers: TMOD (Timer Mode Register) and TCON (Timer Control Register), which are used for activating and configuring timers and counters.

Types of Shift Register

Shift registers are a type of sequential logic circuits that are mainly used for storage of digital data. The shift registers are bit-addressable registers that store only one bit of data. The shift registers are constructed with flip-flops – a group of flip-flops connected as a chain so that the output from one flip-flop becomes the input of the next flip-flop.

All the flip-flops are driven by the clock signals that are implemented by the D-flip-flap. The shift registers are mainly used for serial communication.


These are classified into 4- types:
  • Serial in Serial out (SISO)
  • Serial in Parallel out (SIPO)
  • Parallel in Serial out (PISO)
  • Parallel in Parallel out (PIPO)
D- flipflop register
D- flipflop register.

These are all different types of registers in an 8051 microcontroller. We hope that we have successfully given you relevant content with appropriate program for each register. Furthermore, for any sort of help to know the coding of several other registers, you can contact us by commenting below.

No comments: