Skip to content
Advanced Microprocessor

8051 Pinout, Ports, Timers & Microprocessor Comparison

Open-drain Port 0 pull-ups, Port 3 alternate signals, Timers 0/1 (Modes 0–3), UART baud rate generation, and μP vs μC comparison.

Knova editors11 min readQuick checkSources

8051 Pinout, Timers, Peripherals, and Microprocessor Comparison

The 8051 is housed in a 40-pin Dual In-Line Package. Its 32 I/O pins are divided into four 8-bit ports (P0,P1,P2,P3P_0, P_1, P_2, P_3), each possessing distinct electrical characteristics and dual-function capabilities.

Port Electrical Structures and Pin Functions

  1. Port 0 (Pins 32-39): An open-drain bidirectional port.
    • When used as an ordinary I/O port, Port 0 lacks internal pull-up resistors and requires external pull-up resistors (typically 10 kΩ10\text{ k}\Omega networks) to output logic 1.
    • When interfacing external memory, Port 0 automatically transforms into the time-multiplexed Address/Data Bus (AD0−AD7AD_0-AD_7), using push-pull internal FET drivers.
  2. Port 1 (Pins 1-8): A quasi-bidirectional I/O port equipped with internal pull-up resistors. It serves solely as general-purpose I/O in the standard 8051.
  3. Port 2 (Pins 21-28): A quasi-bidirectional I/O port with internal pull-ups. When external memory is attached, Port 2 emits the higher-order 8 bits of the memory address (A8−A15A_8-A_{15}).
  4. Port 3 (Pins 10-17): A quasi-bidirectional port with internal pull-ups. In addition to general I/O, each pin performs a vital alternate hardware peripheral function:
Pin NumberPort PinAlternate Hardware Function
10P3.0RxD (Serial Asynchronous Input)
11P3.1TxD (Serial Asynchronous Output)
12P3.2INT0‾ (External Hardware Interrupt 0)\overline{INT0} \text{ (External Hardware Interrupt 0)}
13P3.3INT1‾ (External Hardware Interrupt 1)\overline{INT1} \text{ (External Hardware Interrupt 1)}
14P3.4T0 (Timer/Counter 0 External Event Input)T_0 \text{ (Timer/Counter 0 External Event Input)}
15P3.5T1 (Timer/Counter 1 External Event Input)T_1 \text{ (Timer/Counter 1 External Event Input)}
16P3.6WR‾ (External Data Memory Write Strobe)\overline{WR} \text{ (External Data Memory Write Strobe)}
17P3.7RD‾ (External Data Memory Read Strobe)\overline{RD} \text{ (External Data Memory Read Strobe)}

Control Pins

  • EA‾\overline{EA} / VPPV_{PP} (Pin 31 - External Access): When tied to VCCV_{CC} (Logic 1), the 8051 executes instructions from its internal 4 KB ROM from 0000H0000\text{H} to 0FFFH0\text{FFFH}, switching to external ROM for addresses ≥1000H\ge 1000\text{H}. When tied to GNDGND (Logic 0), the internal ROM is bypassed entirely and all code is fetched from external memory.
  • PSEN‾\overline{PSEN} (Pin 29 - Program Store Enable): Active-low read strobe connected to the OE‾\overline{OE} pin of external EPROM/Flash memory. Pulses low twice per machine cycle during instruction fetches.
  • ALE / PROG‾\overline{PROG} (Pin 30): Pulses high at a constant rate of fosc/6f_{\text{osc}} / 6 to demultiplex the AD0−AD7AD_0-AD_7 address bus into an external 74LS373 latch.

Timers and Counters (Timer 0 and Timer 1)

The 8051 provides two software-configurable 16-bit Timer/Counters. Each timer can be configured to count internal machine cycles (Timer mode) or count external negative-going transitions on pin T0T_0 / T1T_1 (Counter mode).

Timer Mode Register (TMOD, Address 89H89\text{H})

D7D_7D6D_6D5D_5D4D_4D3D_3D2D_2D1D_1D0D_0
GATEC/T‾C/\overline{T}M1M_1M0M_0GATEC/T‾C/\overline{T}M1M_1M0M_0

Timer 1 Controls (D7−D4D_7-D_4) \quad | \quad Timer 0 Controls (D3−D0D_3-D_0)

  • GATE: When 00, timer runs whenever control bit TRx=1TR_x = 1. When 11, timer runs only when TRx=1TR_x = 1 and external pin INTx‾\overline{INTx} is high (used for pulse-width measurement).
  • C/T‾C/\overline{T}: 0=Timer mode (counts fosc/12)0 = \text{Timer mode (counts } f_{\text{osc}}/12\text{)}; 1=Counter mode (counts transitions on Tx pin)1 = \text{Counter mode (counts transitions on } T_x\text{ pin)}.
  • M1,M0M_1, M_0 Operating Modes:
    • Mode 0 (0000): 13-bit timer/counter (compatible with 8048).
    • Mode 1 (0101): 16-bit timer/counter (0000H−FFFFH0000\text{H}-\text{FFFFH}, overflows at 65,53665,536).
    • Mode 2 (1010): 8-bit Auto-Reload Timer. TLxTL_x counts from the value pre-loaded in THxTH_x up to FFH\text{FFH}. On overflow, it sets flag TFxTF_x and automatically reloads THxTH_x into TLxTL_x without software intervention. This mode is universally used to generate accurate UART baud rates!
    • Mode 3 (1111): Split timer mode (Timer 0 splits into two independent 8-bit timers).

Baud Rate Generation via Timer 1 Mode 2

In standard 8051 serial communications (Mode 1 8-bit UART), Timer 1 is programmed in Mode 2 (8-bit auto-reload). The baud rate formula with crystal frequency fosc=11.0592 MHzf_{\text{osc}} = 11.0592\text{ MHz} is:

Baud Rate=2SMOD32×fosc12×(256−TH1)\text{Baud Rate} = \frac{2^{SMOD}}{32} \times \frac{f_{\text{osc}}}{12 \times (256 - TH_1)}

Where SMODSMOD is bit 7 of register PCON (Baud Rate Doubler bit). If SMOD=0SMOD = 0:

For 9600 Baud:256−TH1=11,059,200384×9600=3  ⟹  TH1=256−3=253=FDH\text{For } 9600\text{ Baud:} \quad 256 - TH_1 = \frac{11,059,200}{384 \times 9600} = 3 \implies TH_1 = 256 - 3 = 253 = \text{FDH}

Setting TH1=FDHTH_1 = \text{FDH} generates exactly 96009600 baud with 0.00.0% timing error!

Peripherals & Serial Baud Generation

Intel 8051 Timer / Counter & Baud Rate Generator

Configure TMOD register modes, inspect internal 12-clock divider pulses, and witness Mode 2 Auto-Reload generate standard 9600 UART Baud rates.

Timer Modes:
TMOD Register (89H)Value: 20H
GATE
0
C/T'
0
M1
1
M0
0
GATE
0
C/T'
0
M1
0
M0
0
← Timer 1 ConfigurationTimer 0 Configuration →
TH1 Reload Value (Auto-Reload Source):FDH (253 decimal)
FDH (9600 Baud)FAH (4800 Baud)F4H (2400 Baud)
Live Timer Registers & Status
TL1 Register (Counter)FDHDec: 253
Overflow Flag (TF1)LOW (0)No overflow
Computed Serial UART Baud Rate
9600 bps
Target: 9600 Baud · Crystal: 11.0592 MHz (Zero % Error)

• 11.0592 MHz Advantage: Dividing by 12 yields exactly 921.6 kHz. Further dividing by 32 yields 28,800. Setting TH1 = -3 (FDH) gives exactly 9,600 Baud with 0% error.

• Auto-Reload Mechanism: When TL1 increments from FFH to 00H, the hardware automatically re-copies the contents of TH1 into TL1 in 0 machine cycles.

Comparison: Microprocessor vs. Microcontroller

FeatureMicroprocessor (e.g., 8085, 8086)Microcontroller (e.g., 8051, PIC, ARM Cortex-M)
Core ConceptCPU is stand-alone on siliconComplete microcomputer on a single chip
On-Chip MemoryNo on-chip RAM or ROMContains integrated RAM, ROM/Flash, and EEPROM
Peripheral ICsRequires external 8255, 8257, 8259, 8251Timers, counters, UART, and I/O ports built-in
Design FlexibilityDesigner customizes memory and I/O sizeFixed internal resources; expansion possible
\text{System Cost & Size}Higher cost, large PCB footprintCompact, low component count, highly cost-effective
Power ConsumptionHigher power consumptionUltra-low power (Supports IDLE and Power-Down modes)
Application FocusGeneral-purpose computing (PCs, servers)Dedicated embedded control (Appliances, automotive, IoT)
Try it
8051 Port 0 Electrical Characteristic: Why must an external resistor pull-up pack be connected to Port 0 when used as an ordinary output port?

Sources

  1. 1.Intel 8051 Microcontroller Datasheet · reference · Wikipedia (opens in a new tab)

Was this chapter useful?

Editors read every answer.

Star this chapter

Each star goes once to every reader who improved this chapter.

Finished reading?

Mark it to keep your place in the course.