The 8051 Microcontroller
The 8051 is a classic 8-bit microcontroller introduced by Intel in 1980. It is a member of the
MCS-51 family of microcontrollers. Despite the introduction of more powerful and advanced
microcontrollers, the 8051 remains a popular choice for educational purposes and many basic
embedded systems due to its straightforward architecture, simple instruction set, and robust
on-chip peripherals.
1. Key Features
The 8051 is known for its integrated "computer-on-a-chip" features, which include:
● CPU (Central Processing Unit): An 8-bit CPU.
● Memory:
○ Internal ROM/Program Memory: 4 KB of on-chip ROM for storing the program.
○ Internal RAM/Data Memory: 128 bytes of on-chip RAM for data storage.
● I/O Ports: Four 8-bit bidirectional I/O ports (Port 0, Port 1, Port 2, and Port 3) for a total of
32 I/O lines.
● Timers/Counters: Two 16-bit timers/counters (Timer 0 and Timer 1) for timing events and
counting pulses.
● Serial Communication: A full-duplex serial port (UART - Universal Asynchronous
Receiver-Transmitter).
● Interrupts: A five-source interrupt system with two external and three internal interrupts.
● Architecture: It uses a modified Harvard architecture, which allows simultaneous access
to program memory and data memory.
● Special Function Registers (SFRs): A dedicated memory area from address 80H to
FFH to control and manage the 8051's on-chip peripherals.
2. Architecture and Pin Diagram
The 8051 is typically housed in a 40-pin DIP (Dual In-line Package). The pins are dedicated to
various functions, including power supply, clock input, control signals, and the four I/O ports.
● VCC (Pin 40): The power supply pin, typically +5V.
● GND (Pin 20): Ground.
● XTAL1 and XTAL2 (Pins 18 & 19): These pins are for connecting an external oscillator
(e.g., a quartz crystal) to provide the clock frequency for the CPU.
● RST (Pin 9): Reset pin. A high pulse on this pin resets the microcontroller.
● EA/VPP (Pin 31): External Access Enable. This pin determines whether the
microcontroller executes code from internal or external program memory.
● PSEN (Pin 29): Program Store Enable. This is an output signal used to enable external
program memory.
● ALE (Pin 30): Address Latch Enable. This signal is used to demultiplex the address and
data bus for external memory access.
● Ports (P0, P1, P2, P3): The four 8-bit ports. Some pins on Port 3 also have alternative
functions for peripherals like the serial port (RXD, TXD) and external interrupts (INT0,
INT1).
3. Memory Organization
The 8051 has separate memory spaces for program and data, a characteristic of the Harvard
architecture.
● Program Memory (ROM): Stores the instructions to be executed. The original 8051 had
4 KB of internal ROM, with a total addressable space of 64 KB, which could be expanded
with external memory.
● Data Memory (RAM):
○ Internal RAM (128 bytes): This is the on-chip RAM, located from address 00H to
7FH. It is divided into:
■ Register Banks (Addresses 00H-1FH): Four banks of eight registers (R0 to
R7). Only one bank is active at a time, selected by the RS0 and RS1 bits in
the PSW register.
■ Bit-Addressable Area (Addresses 20H-2FH): This area contains 16 bytes,
where each individual bit can be addressed directly.
■ General Purpose RAM (Addresses 30H-7FH): A scratchpad area for
general-purpose data storage.
○ Special Function Registers (SFRs) (Addresses 80H-FFH): These are registers
used to control the 8051's peripherals. They include the Accumulator (ACC), B
register (B), Program Status Word (PSW), Stack Pointer (SP), Data Pointer
(DPTR), and registers for the timers and serial port.
4. Instruction Set and Addressing Modes
The 8051 has a powerful instruction set with a wide range of instructions for data transfer,
arithmetic, logic, and bit-level manipulation. The addressing modes define how the operand's
address is specified in an instruction.
● Immediate Addressing: The data is part of the instruction itself.
○ MOV A, #55H (moves the value 55H to the Accumulator).
● Register Addressing: The operand is in one of the eight general-purpose registers
(R0-R7).
○ ADD A, R5 (adds the value in R5 to the Accumulator).
● Direct Addressing: The operand's address is specified directly in the instruction.
○ MOV A, 30H (moves the value at internal RAM address 30H to the Accumulator).
● Register Indirect Addressing: The address of the operand is held in a register, typically
R0 or R1.
○ MOV A, @R0 (moves the value at the address pointed to by R0 to the
Accumulator).
● Indexed Addressing: Used to access data from the program memory. The effective
address is the sum of a base register (like the DPTR) and the Accumulator.
○ MOVC A, @A+DPTR (moves the code byte from the address (A + DPTR) into the
Accumulator).
5. Programming the 8051
The 8051 can be programmed using both assembly language and high-level languages like C.
● Assembly Language: Provides direct control over the microcontroller's hardware,
resulting in highly optimized and efficient code. However, it is more time-consuming to
write and debug.
● C Language: Compilers like Keil C51 are widely used. C programming is faster and more
portable than assembly. While C code is generally less memory-efficient, modern
compilers can produce very compact and fast code.
6. Common Applications
The 8051's simplicity and reliability make it suitable for a wide variety of embedded systems,
including:
● Consumer Electronics: Remote controls, toys, home appliances like washing machines
and microwave ovens.
● Automotive: Engine control, anti-lock braking systems (ABS), and in-car entertainment.
● Industrial Automation: Robotics, process control systems, and machinery.
● Medical Devices: Simple medical instruments and devices.
● Communications: Modems, pagers, and other networking equipment.