RRB JE CBT2 : EXPERT
27 May

8051 MICROCONTROLLER – COMPLETE NOTES

Introduction

The 8051 Microcontroller is an 8-bit microcontroller built in a 40-pin DIP (Dual Inline Package). It is one of the most widely used microcontrollers in embedded systems because of its simple architecture, built-in peripherals, and capability to interface with external memory.The 8051 contains both Program Memory (ROM) and Data Memory (RAM). Program memory stores the instructions permanently, whereas data memory stores temporary data, variables, and intermediate results generated during program execution.


BASIC FEATURES OF 8051

FeatureSpecification
Data Bus Width8-bit
Package40-pin DIP
Internal RAM128 Bytes
Internal ROM (Code Memory)4 KB
External Program Memory64 KB
External Data Memory64 KB
Timer/Counters2
Interrupts5
Serial Port1
I/O Ports4
Total I/O Pins32

MEMORY ORGANIZATION OF 8051

The memory of 8051 is divided into two major categories:

1. Program Memory (Code Memory)

Program memory stores the instructions to be executed by the microcontroller.

  • Internal Program Memory = 4 KB ROM
  • External Program Memory = 64 KB

2. Data Memory (RAM)

Data memory stores:

  • Variables
  • Temporary data
  • Intermediate results
  • Stack contents

The internal data memory size is:128 Bytes RAM


INTERNAL RAM ORGANIZATION

The internal RAM consists of 128 bytes.

Address Range

Memory AreaAddress Range
Register Banks00H – 1FH
Bit Addressable RAM20H – 2FH
General Purpose RAM30H – 7FH

Register Banks

The lower 32 bytes of RAM contain four register banks.

Total Register Banks = 4

Each register bank contains:R0 to R7 (8 Registers)Therefore:Total Registers = 4 × 8 = 32 Registers

Register Bank Address Mapping

RS1RS0Active BankAddress Range
00Bank 000H – 07H
01Bank 108H – 0FH
10Bank 210H – 17H
11Bank 318H – 1FH

The active register bank is selected using the RS0 and RS1 bits of the Program Status Word (PSW) register.


BIT ADDRESSABLE MEMORY

A special feature of the 8051 is the presence of Bit Addressable RAM.

Address Range

20H – 2FH

Size

  • Total Bytes = 16
  • Bits per Byte = 8

Therefore:16 × 8 = 128 Addressable BitsEach bit can be accessed directly through bit addresses ranging from:00H – 7FHThis allows efficient manipulation of individual bits without affecting other bits in the same byte.


SPECIAL FUNCTION REGISTERS (SFRs)

The Special Function Registers (SFRs) are used to control and monitor various hardware resources of the microcontroller.

SFR Address Range

80H – FFHThe SFR area occupies the upper 128-byte address space of the 8051.


Importance of SFRs

SFRs are used for:

  • Timer control
  • Interrupt management
  • Serial communication
  • Port control
  • Power control
  • Processor configuration

They provide direct control over hardware resources and peripheral operations.


ACCUMULATOR REGISTER

The Accumulator (A) is the most important register in the 8051.It is extensively used in:

  • Arithmetic operations
  • Logical operations
  • Data transfer operations
  • Comparisons

Most instructions either use the accumulator as a source operand, destination operand, or both.

Address of Accumulator

0E0HThe accumulator is located in the SFR area.


STACK POINTER (SP)

The Stack Pointer (SP) is a special-purpose register used to store the address of the top of the stack.The stack is used for:

  • Temporary data storage
  • Return addresses during subroutine calls
  • Interrupt handling

Reset Value of Stack Pointer

After reset:SP = 07HThis means the first PUSH operation stores data at:08HThe stack grows upward toward higher memory addresses.


Importance of Default SP Value

  • Enables immediate stack operation after reset.
  • Protects register locations from accidental overwrite.
  • Provides a predefined stack starting location.

I/O PORTS OF 8051

The 8051 contains four parallel I/O ports.

PortPins
Port 08
Port 18
Port 28
Port 38

Total I/O Pins

4 × 8 = 32 Pins


PORT 0

Main Functions

Port 0 is a dual-purpose port.It can operate as:

  • General-purpose bidirectional I/O port
  • Multiplexed Address/Data Bus during external memory access

Port 0 During External Memory Access

Port 0 provides:

Lower Address Byte

A0 – A7during the first part of the machine cycle.

Data Bus

D0 – D7during the second part of the machine cycle.Thus Port 0 functions as:AD0 – AD7(Address/Data Multiplexed Bus)


Working of Port 0

Address Phase

  • Port 0 outputs lower address bits A0–A7.
  • ALE (Address Latch Enable) becomes active.
  • External latch captures the address.

Data Phase

  • Port 0 switches to data mode.
  • Data D0–D7 is transferred.
  • RD or WR signals control memory read/write operation.

Importance of Port 0

Port 0 enables efficient use of pins by allowing the same pins to carry both address and data information at different times.


PORT 1

Port 1 is a simple general-purpose bidirectional I/O port.

Important Feature

Port 1 has no dual function.It is used exclusively for:

  • Input operations
  • Output operations

This makes Port 1 the simplest port of the 8051.


PORT 2

Port 2 is another dual-purpose port.It can function as:

  • General-purpose I/O port
  • High-order Address Bus during external memory access

Main Role During External Memory Access

Port 2 provides:

High Address Byte

A8 – A15The high-order address remains stable throughout the memory access cycle.


Memory Expansion Role

By combining:

  • Port 0 → A0–A7
  • Port 2 → A8–A15

the 8051 generates a complete 16-bit address.Therefore, the maximum addressable external memory becomes:2¹⁶ = 65,536 Bytes = 64 KB


Example

For address:1234H

Address PartValue
High Byte12H
Low Byte34H

Port 2 outputs:12HPort 0 outputs:34HThis allows access to memory location 1234H.


PORT 3

Port 3 is a general-purpose I/O port having multiple special functions.Besides I/O operations, it provides control signals related to:

  • Serial communication
  • External interrupts
  • Timer inputs
  • External memory control signals

Thus Port 3 is the most multifunctional port of the 8051.


EXTERNAL MEMORY ACCESS IN 8051

When external memory is used, the microcontroller must generate a 16-bit address.

Address Generation

PortFunction
Port 0Lower Address Byte (A0–A7) and Data Bus
Port 2Higher Address Byte (A8–A15)

Address Latching

Since Port 0 carries both address and data:

  • ALE signal is generated.
  • External latch stores A0–A7.
  • Port 0 later switches to data transfer.

This technique is called:Address/Data Multiplexing


DATA POINTER (DPTR)

The Data Pointer (DPTR) is a 16-bit register used for accessing external memory.


External Memory Access

The 8051 accesses external memory primarily through:Indirect Addressing using DPTRThe DPTR stores the 16-bit address of the external memory location.


MOVX Instruction

External data memory access is performed using the MOVX instruction.Example:

MOVX A,@DPTR

This instruction transfers data from the external memory location pointed to by DPTR into the accumulator.


Importance of DPTR

  • Holds 16-bit external memory address.
  • Enables access to external RAM.
  • Supports indirect addressing mechanism.

QUICK REVISION

Memory

  • Internal RAM = 128 Bytes
  • Internal ROM = 4 KB
  • External Data Memory = 64 KB
  • External Program Memory = 64 KB

Register Banks

  • Total Banks = 4
  • Registers per Bank = 8
  • Total Registers = 32

Bit Addressable RAM

  • Address Range = 20H – 2FH
  • Size = 16 Bytes
  • Total Bits = 128

SFR Range

  • 80H – FFH

Accumulator Address

  • 0E0H

Stack Pointer Reset Value

  • 07H

I/O Ports

  • Total Ports = 4
  • Total I/O Pins = 32

Port Functions

PortMajor Function
Port 0I/O + AD0–AD7
Port 1Only I/O
Port 2I/O + A8–A15
Port 3I/O + Special Functions

External Memory Access

  • Port 0 → Lower Address + Data
  • Port 2 → Higher Address
  • ALE → Address Latching
  • DPTR → External Memory Addressing
  • MOVX → External Memory Transfer Instruction
Comments
* The email will not be published on the website.