3.0 The 8051 Microcontroller: A Detailed Analysis
3.1 Overview and Key Features
Introduced by Intel in 1981, the 8051 is an 8-bit microcontroller referred to as a “system on a chip.” Its code compatibility across different manufacturers has led to numerous versions with varying speeds and memory amounts.
Core Features:
- 4KB on-chip program memory (ROM)
- 128 bytes on-chip data memory (RAM)
- Four 8-bit I/O ports (P0, P1, P2, P3)
- Two 16-bit timers/counters
- One full-duplex serial port
- Six interrupt sources (2 external, 2 timer, 1 serial)
- 8-bit bidirectional data bus and 16-bit unidirectional address bus
- 32 general-purpose 8-bit registers
3.2 8051 Family Variants
The 8051 family includes several “flavors” with different feature sets.
| Feature | 8051 | 8052 | 8031 |
| ROM (bytes) | 4K | 8K | 0K (ROM-less) |
| RAM (bytes) | 128 | 256 | 128 |
| Timers | 2 | 3 | 2 |
| I/O Pins | 32 | 32 | 32 |
| Serial Port | 1 | 1 | 1 |
| Interrupt Sources | 6 | 8 | 6 |
3.3 I/O Ports and Programming
The 8051 has four 8-bit ports (P0, P1, P2, P3), totaling 32 I/O pins. Upon reset, all ports are configured as inputs. Writing a ‘0’ to a port bit configures it as an output, while writing a ‘1’ configures it as an input.
- Port 0 (Pins 32-39): An open-drain port that requires external pull-up resistors. It serves a dual role as a multiplexed address (A0-A7) and data (D0-D7) bus when accessing external memory.
- Port 1 (Pins 1-8): A standard I/O port with internal pull-up resistors.
- Port 2 (Pins 21-28): Has internal pull-up resistors. It serves a dual role by providing the high-order address bits (A8-A15) when accessing external memory.
- Port 3 (Pins 10-17): Has internal pull-up resistors and provides access to several special features:
- P3.0/P3.1: RxD/TxD (Serial Communication)
- P3.2/P3.3: INT0/INT1 (External Interrupts)
- P3.4/P3.5: T0/T1 (Timer Inputs)
- P3.6/P3.7: WR/RD (External Memory Write/Read Strobes)
3.4 Essential Hardware Pins and Functions
- Vcc (Pin 40) / Gnd (Pin 20): Power supply (+5V) and ground.
- XTAL1, XTAL2 (Pins 18, 19): Connections for an external quartz crystal to drive the on-chip oscillator.
- RST (Pin 9): Active-high reset pin. A high pulse for at least two machine cycles resets the microcontroller, clearing registers and setting the Program Counter to 0000H.
- EA (External Access, Pin 31): Active-low input. Connected to Vcc to access on-chip ROM. Connected to Gnd to fetch code from external program memory (required for ROM-less variants like 8031).
- PSEN (Program Store Enable, Pin 29): Active-low output used as the read strobe for external program memory.
- ALE (Address Latch Enable, Pin 31): Active-high output used to demultiplex the address and data bus on Port 0. When ALE=1, Port 0 provides the lower address bits (A0-A7).