Registers in 8051 Microcontroller

Registers in 8051 microcontroller is mainly classified into

  1. General purpose registers
  2. Special function registers (SFRs)

General Purpose Registers in 8051

  • Totally 34 general purpose registers or working registers. They are used to store data.
  • Two of these A and B hold results of many instructions, particularly arithmetic and logical operations of 8051 CPU.
  • The other 32 are in four register banks, RB0 –RB3 of eight registers each.

Accumulator

  • The Accumulator (A register) is used for many operations like Addition, Subtraction, Multiplication, Division and Boolean bit logical operations.
  • It is also used for data transfer between 8051 and external memories, I/O devices.

B Register

  • The B register is used to do arithmetic operations such as multiplication and division with Accumulator.
  • B register may be used to store the data and it has no other functions.

R Registers (R0-R7)

  • These registers are from the data memory location starting from 00h. There are 4 register banks each consisting of eight 8-bit registers as shown in diagram.
  • R registers is a common name for 8 general-purpose registers (R0, R1, R2 …R7). Similar to the accumulator, they are used for temporary storing variables and intermediate results during operation.
r0 to r7 registers in 8051 microcontroller

Which one of these banks is to be active depends on two bits of the PSW Register. Active bank is a bank the registers of which are currently used.

Special Function Registers in 8051

  • Programmers should not use the addresses in the range 80H to FFH (other than SFR) as it is used by INTEL CORPORATION for expansion functions of 8051.

Direct Addressed Memory Address (SFR)

Special Function Register

80

P0

81

SP

82

DPL

83

DPH

87

TCON

88

TMOD

89

TL0

8A

TL1

8B

TH0

8C

TH1

90

P1

98

SCON

99

SBUF

A0

P2

A8

IE

B0

P3

B8

IP

D0

PSW

E0

ACC

F0

B

Program Status Word (PSW)

Click here to read in details.

Stack Pointer (SP)

  • The register to access the stack is called Stack Pointer.
  • The stack pointer (SP) is an 8-bit register within the SFR area, with the address 81H and it can point an address location between 00h to FFh.
  • Stack pointer is used to hold the address of Top of the Stack. The address held in the SP is the location in internal RAM where the last byte of data was stored by a stack operation.
  • After reset it is initialized to the value 07H.

Data Pointer (DPTR)

  • The Data Pointer (DPTR) is the 8051 only user-accessible 16-bit (2-byte) register.
  • DPTR, as the name suggests, is used to point to data. It is used by a number of commands which allow the 8051 to access external memory.
  • When the 8051 accesses external memory it will access external memory at the address indicated by DPTR.

Program Counter (PC)

  • The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to execute is found in memory.
  • When the 8051 is initialized, PC always starts at 0000h and is incremented each time an instruction is executed.
  • It is important to note that PC isn’t always incremented by one. Since some instructions require 2 or 3 bytes the PC will be incremented by 2 or 3 in these cases.
  • There are some instructions such as jump, call and return which can modify the PC and can change the sequence of address in it.

P0, P1, P2, P3 - Input/Output Registers

Registers in 8051 Microcontroller
  • Microcontroller 8051 has 4 ports. Each port is of 8-bit and can works as input as well as output.
  • Each bit within these ports affects the state and performance of appropriate pin of the microcontroller. Thus, bit logic state is reflected on appropriate pin as a voltage (0 or 5 V) and vice versa, voltage on a pin reflects the state of appropriate port bit.
  • As mentioned, port bit state affects performance of port pins, i.e. whether they will be configured as inputs or outputs.
  • If a bit is cleared (0), the appropriate pin will be configured as an output, while if it is set (1), the appropriate pin will be configured as an input.
  • Upon reset and power-on, all port bits are set (1), which means that all appropriate pins will be configured as inputs.

Timer Registers T0 and T1

  • Microcontroller 8051 has two timer/counters namely timer 0 and timer 1. Size of each timer is 16 bits wide. Since the architecture of 8051 is 8 bits, the timers are separated into two 8-bit registers.
  • The timer 0 is divided into low byte of timer 0 (TL0) and high byte of timer 0 (TH0). Same way timer 1 as TL1 and TH1.
timer registers in 8051 microcontroller.jpg
  • The timer registers TL0, TL1, TH0 and TH1 can be addressed by its location like any other registers.
  • Since the timer is virtually 16-bit register, the largest value it can store is 65535. In case of exceeding this value, the timer will be automatically cleared and counting starts from 0. This condition is called an overflow.
  • Two registers TMOD and TCON are closely connected to this timer and control its operation.

Timer Control (TCON) Register

  • TCON register is also one of the registers whose bits are directly in control of timer operation.
  • Only 4 bits of this register are used for this purpose, while rest of them is used for interrupt control to be discussed later.
Registers in 8051 Microcontroller

TF1 bit is automatically set on the Timer 1 overflow.

TR1 bit enables the Timer 1.

  • 1 – Timer 1 is enabled.
  • 0 – Timer 1 is disabled.

TF0 bit is automatically set on the Timer 0 overflow.

TR0 bit enables the timer 0.

  • 1 – Timer 0 is enabled.
  • 0 – Timer 0 is disabled.

TMOD Register (Timer Mode)

The TMOD register selects the operational mode of the timers T0 and T1. As seen in figure below, the low 4 bits (bit0 – bit3) refer to the timer 0, while the high 4 bits (bit4 – bit7) refer to the timer 1.

format for tmod register in 8051 microcontroller

Bits of this register have the following function:

  • GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3):
  • 1 – Timer 1 operates only if the INT1 bit is set.
  • 0 – Timer 1 operates regardless of the logic state of the INT1 bit.
    • C/T1 selects pulses to be counted up by the timer/counter 1:
  • 1 – Timer counts pulses brought to the T1 pin (P3.5).
  • 0 – Timer counts pulses from internal oscillator.
    • T1M1, T1M0 These two bits select the operational mode of the Timer 1.

T1M1

T1M0

Mode

Description

0

0

0

13-bit timer

0

1

1

16-bit timer

1

0

2

8-bit auto-reload

1

1

3

Split mode

GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):

  • 1 – Timer 0 operates only if the INT0 bit is set.
  • 0 – Timer 0 operates regardless of the logic state of the INT0 bit.
    • C/T0 selects pulses to be counted up by the timer/counter 0:
  • 1 – Timer counts pulses brought to the T0 pin (P3.4).
  • 0 – Timer counts pulses from internal oscillator.
    • T0M1, T0M0 These two bits select the operational mode of the Timer 0.

T0M1

T0M0

Mode

Description

0

0

0

13-bit timer

0

1

1

16-bit timer

1

0

2

8-bit auto-reload

1

1

3

Split mode

SBUF register

format for SBUF register in 8051 microcontroller

One of the microcontroller features making it so powerful is an integrated UART, better known as a serial port. It is a full-duplex port, thus being able to transmit and receive data simultaneously and at different baud rates.

Serial data transmit is nothing but writing to the SBUF register, while data receive represents reading the same register. The microcontroller takes care of not making any error during data transmission.

Serial Port Control (SCON) Register

  • Serial port must be configured prior to being used. In other words, it is necessary to determine how many bits is contained in one serial “word”, baud rate and synchronization clock source.
  • The whole process is in control of the bits of the SCON register (Serial Control).
format for SCON register in 8051 microcontroller
  • SM0 – Serial port mode bit 0 is used for serial port mode selection.
  • SM1 – Serial port mode bit 1.
  • SM2 – Serial port mode 2 bit, also known as multiprocessor communication enable bit. When set, it enables multiprocessor communication in mode 2 and 3, and eventually mode 1. It should be cleared in mode 0.
  • REN – Reception Enable bit enables serial reception when set. When cleared, serial reception is disabled.
  • TB8 – Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of transmitting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th
  • RB8 – Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.
  • TI – Transmit Interrupt flag is automatically set at the moment the last bit of one byte is sent. It’s a signal to the processor that the line is available for a new byte transmitted. It must be cleared from within the software.
  • RI – Receive Interrupt flag is automatically set upon one byte receive. It signals that byte is received and should be read quickly prior to being replaced by a new data. This bit is also cleared from within the software.

PCON register

Power saving mode, power down and idle mode in 8051

The purpose of the Register PCON bits is:

  • SMOD Baud rate is twice as much higher by setting this bit.
  • GF1 General-purpose bit (available for use).
  • GF1 General-purpose bit (available for use).
  • GF0 General-purpose bit (available for use).
  • PD By setting this bit the microcontroller enters the Power Down
  • IDL By setting this bit the microcontroller enters the Idle

IE (Interrupt Enable) Register

format for IE interrupt enable register in 8051 microcontroller

EA – global interrupt enable/disable:

  • 0 – disables all interrupt requests.
  • 1 – enables all individual interrupt requests.

ES – enables or disables serial interrupt:

  • 0 – UART system cannot generate an interrupt.
  • 1 – UART system enables an interrupt.

ET1 – bit enables or disables Timer 1 interrupt:

  • 0 – Timer 1 cannot generate an interrupt.
  • 1 – Timer 1 enables an interrupt.

EX1 – bit enables or disables external 1 interrupt:

  • 0 – change of the pin INT0 logic state cannot generate an interrupt.
  • 1 – enables an external interrupt on the pin INT0 state change.

ET0 – bit enables or disables timer 0 interrupt:

  • 0 – Timer 0 cannot generate an interrupt.
  • 1 – enables timer 0 interrupt.

EX0 – bit enables or disables external 0 interrupt:

  • 0 – change of the INT1 pin logic state cannot generate an interrupt.
  • 1 – enables an external interrupt on the pin INT1 state change.

IP (Interrupt Priority) Register

The IP register bits specify the priority level of each interrupt (high or low priority).

Registers in 8051 Microcontroller

PS – Serial Port Interrupt priority bit

  • Priority 0
  • Priority 1

PT1 – Timer 1 interrupt priority

  • Priority 0
  • Priority 1

PX1 – External Interrupt INT1 priority

  • Priority 0
  • Priority 1

PT0 – Timer 0 Interrupt Priority

  • Priority 0
  • Priority 1

PX0 – External Interrupt INT0 Priority

  • Priority 0
  • Priority 1

Recent posts

2 thoughts on “Registers in 8051 Microcontroller”

  1. Fine way of describing, and nice article to obtain data concerning my presentation topic, which i am going to present in institution of higher education.

Comments are closed.