Knowledge / Electronics and Communication Engineering / 8051 microcontroller

8051 microcontroller

Electronics and Communication Engineering (B.E./B.Tech) · Microprocessors and embedded · free study notes for exams, placements and interviews

In short

The 8051 is an 8-bit CISC microcontroller introduced by Intel in 1980 that puts a CPU, ROM, RAM, timers, a serial port, four I/O ports and an interrupt system on one chip. Its register and memory map is small enough to be learnt completely, so Indian universities use it as the standard teaching microcontroller and lab kit (8051/AT89C51/AT89S52 trainer boards), and GATE EC/EE, ISRO, DRDO, BARC, BEL and ESE papers ask register-level questions on it almost every year. Placement interviews at embedded firms (Bosch, Continental, Tata Elxsi, KPIT, L&T Technology Services, HCL, Wipro VLSI/embedded, Mindtree) use 8051 questions to test whether a candidate actually understands registers, stacks, timers and interrupts rather than just library calls. Though new designs now use ARM Cortex-M or RISC-V, 8051 cores still ship inside USB controllers, smart cards, keyboard controllers, remote controls and ASIC/FPGA soft cores.

Explained

Architecture and on-chip resources

Pin diagram and signals (40-pin DIP)

Internal RAM map and special function registers

Instruction set and addressing modes

Timers, serial port and interrupts (8051-specific registers)

Programming, tools and 8051 in practice

Key points

Formulas and examples

Machine cycle time Tmc = 12 / fosc (s); fosc = crystal frequency in Hz
Timer tick (mode 1, C/T = 0) = Tmc; maximum delay (mode 1) = 65536 × Tmc; (mode 2) = 256 × Tmc
Count to load (mode 1) = 65536 − (required delay / Tmc), written as THx:TLx in hex
Count to load (mode 2, auto-reload) = 256 − (required delay / Tmc), written into THx
UART baud rate (mode 1) = fosc / (12 × 32 × (256 − TH1)) with SMOD = 0; doubled when SMOD = 1
Equivalently baud = (Timer-1 overflow rate) / 32, overflow rate = fosc / (12 × (256 − TH1))
Instruction execution time = (number of machine cycles) × Tmc
Delay-loop time ≈ (loop body machine cycles) × (iterations) × Tmc

Example 1 - machine cycle and instruction timing. Crystal = 11.0592 MHz.

Example 2 - 20 ms delay with Timer 0, mode 1, fosc = 12 MHz.

Example 3 - serial port at 9600 baud, 8-bit data, 1 stop bit, fosc = 11.0592 MHz.

Example 4 - arithmetic and flags. A = 9CH, R2 = 7BH; execute ADD A,R2.

Example 5 - square-wave frequency on a port pin. Timer 0 in mode 2 with TH0 = 9CH, fosc = 12 MHz, the pin toggled in the ISR.

Feature8051 (classic)8052 / AT89S52
On-chip code memory4 KB ROM8 KB (ROM on 8052, flash on AT89S52)
Internal RAM128 bytes256 bytes
TimersT0, T1T0, T1, T2 (with capture)
Interrupt sources56
ProgrammingMask ROM / EPROMIn-system serial (ISP)
Timer modeSizeReloadTypical use
013-bitManualLegacy, rarely used
116-bitManualLong single delays
28-bitAutomatic (from TH)Baud rate, periodic tick
3Split 8-bit + 8-bit (T0)ManualExtra timer when T1 is busy with UART

Where it is used

Interview questions

Common mistakes

Related topics

8085 and 8086 microprocessors · ARM and embedded C · Microcontroller peripherals: timers, ADC, PWM and interrupts · Embedded interfaces: UART, SPI and I2C · Real-time operating systems · Internet of Things basics

Open in the Knowledge reader →Find jobs →