8051 MICROCONTROLLER – COMPLETE NOTES
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.
| Feature | Specification |
|---|---|
| Data Bus Width | 8-bit |
| Package | 40-pin DIP |
| Internal RAM | 128 Bytes |
| Internal ROM (Code Memory) | 4 KB |
| External Program Memory | 64 KB |
| External Data Memory | 64 KB |
| Timer/Counters | 2 |
| Interrupts | 5 |
| Serial Port | 1 |
| I/O Ports | 4 |
| Total I/O Pins | 32 |
The memory of 8051 is divided into two major categories:
Program memory stores the instructions to be executed by the microcontroller.
Data memory stores:
The internal data memory size is:128 Bytes RAM
The internal RAM consists of 128 bytes.
| Memory Area | Address Range |
|---|---|
| Register Banks | 00H – 1FH |
| Bit Addressable RAM | 20H – 2FH |
| General Purpose RAM | 30H – 7FH |
The lower 32 bytes of RAM contain four register banks.
Each register bank contains:R0 to R7 (8 Registers)Therefore:Total Registers = 4 × 8 = 32 Registers
| RS1 | RS0 | Active Bank | Address Range |
|---|---|---|---|
| 0 | 0 | Bank 0 | 00H – 07H |
| 0 | 1 | Bank 1 | 08H – 0FH |
| 1 | 0 | Bank 2 | 10H – 17H |
| 1 | 1 | Bank 3 | 18H – 1FH |
The active register bank is selected using the RS0 and RS1 bits of the Program Status Word (PSW) register.
A special feature of the 8051 is the presence of Bit Addressable RAM.
20H – 2FH
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.
The Special Function Registers (SFRs) are used to control and monitor various hardware resources of the microcontroller.
80H – FFHThe SFR area occupies the upper 128-byte address space of the 8051.
SFRs are used for:
They provide direct control over hardware resources and peripheral operations.
The Accumulator (A) is the most important register in the 8051.It is extensively used in:
Most instructions either use the accumulator as a source operand, destination operand, or both.
0E0HThe accumulator is located in the SFR area.
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:
After reset:SP = 07HThis means the first PUSH operation stores data at:08HThe stack grows upward toward higher memory addresses.
The 8051 contains four parallel I/O ports.
| Port | Pins |
|---|---|
| Port 0 | 8 |
| Port 1 | 8 |
| Port 2 | 8 |
| Port 3 | 8 |
4 × 8 = 32 Pins
Port 0 is a dual-purpose port.It can operate as:
Port 0 provides:
A0 – A7during the first part of the machine cycle.
D0 – D7during the second part of the machine cycle.Thus Port 0 functions as:AD0 – AD7(Address/Data Multiplexed Bus)
Port 0 enables efficient use of pins by allowing the same pins to carry both address and data information at different times.
Port 1 is a simple general-purpose bidirectional I/O port.
Port 1 has no dual function.It is used exclusively for:
This makes Port 1 the simplest port of the 8051.
Port 2 is another dual-purpose port.It can function as:
Port 2 provides:
A8 – A15The high-order address remains stable throughout the memory access cycle.
By combining:
the 8051 generates a complete 16-bit address.Therefore, the maximum addressable external memory becomes:2¹⁶ = 65,536 Bytes = 64 KB
For address:1234H
| Address Part | Value |
|---|---|
| High Byte | 12H |
| Low Byte | 34H |
Port 2 outputs:12HPort 0 outputs:34HThis allows access to memory location 1234H.
Port 3 is a general-purpose I/O port having multiple special functions.Besides I/O operations, it provides control signals related to:
Thus Port 3 is the most multifunctional port of the 8051.
When external memory is used, the microcontroller must generate a 16-bit address.
| Port | Function |
|---|---|
| Port 0 | Lower Address Byte (A0–A7) and Data Bus |
| Port 2 | Higher Address Byte (A8–A15) |
Since Port 0 carries both address and data:
This technique is called:Address/Data Multiplexing
The Data Pointer (DPTR) is a 16-bit register used for accessing external memory.
The 8051 accesses external memory primarily through:Indirect Addressing using DPTRThe DPTR stores the 16-bit address of the external memory location.
External data memory access is performed using the MOVX instruction.Example:
MOVX A,@DPTRThis instruction transfers data from the external memory location pointed to by DPTR into the accumulator.
| Port | Major Function |
|---|---|
| Port 0 | I/O + AD0–AD7 |
| Port 1 | Only I/O |
| Port 2 | I/O + A8–A15 |
| Port 3 | I/O + Special Functions |