The AT89S52 8051 microcontroller by Atmel is one of the most widely taught microcontrollers in Indian engineering colleges. Despite being a decades-old architecture, 8051 programming remains a fundamental subject in BE/BTech Electronics and Computer Science programmes across India. This guide helps Indian students get started with AT89S52 programming using the most accessible tools available in Indian educational settings.
Table of Contents
- Why 8051 is Still Taught in India
- AT89S52 Key Specifications
- Hardware Setup and Programmer
- Keil μVision Setup
- First Program: LED Blink
- Understanding 8051 Ports and I/O
- Timers and Interrupts
- Frequently Asked Questions
Why 8051 is Still Taught in India
The 8051 microcontroller family has been a staple of Indian engineering education since the 1990s. It remains relevant for several reasons:
- Curriculum alignment: VTU, JNTU, Mumbai University, and most Indian technical universities include 8051 in their Microprocessors/Microcontrollers subject
- Low cost: AT89S52 chips cost ₹30–₹60 each — among the cheapest MCUs available in India
- Simple architecture: 8051’s Von Neumann architecture with Harvard-inspired implementation is ideal for teaching memory organisation, addressing modes, and assembly language
- Industry use: Industrial control applications still use 8051 variants for their robustness and long lifecycle
- Learning foundation: Understanding 8051 makes it easier to learn modern ARM architectures
AT89S52 Key Specifications
- Architecture: 8-bit 8051 compatible
- Clock: Up to 33 MHz (typically used at 11.0592 MHz for UART timing)
- Flash: 8KB (ISP programmable via SPI)
- RAM: 256 bytes on-chip SRAM
- I/O Ports: P0, P1, P2, P3 (32 I/O pins total)
- Timers: 3× 16-bit timers (Timer 0, 1, 2)
- Serial: Full-duplex UART
- Interrupts: 6 interrupt sources (INT0, INT1, Timer0, Timer1, Timer2, Serial)
- Package: 40-pin DIP (breadboard friendly)
- India Price: ₹30–₹60 per chip
Hardware Setup and Programmer
To program AT89S52 using ISP (In-System Programming via SPI), you need a USBasp programmer:
- USBasp programmer: ₹100–₹200 from Indian electronics suppliers
- AT89S52 on breadboard with 11.0592 MHz crystal and 30pF capacitors
- Reset circuit: 10K resistor from VCC to RESET pin, 10μF capacitor from RESET to GND
- AVRDUDE software for flashing (despite the name, it supports AT89S52)
Alternatively, many Indian college labs use parallel programmers (like the Xeltek or MicroPro universal programmer) to burn programs into the AT89S52.
Minimum circuit connections:
- VCC (pin 40) → 5V, GND (pin 20) → GND
- XTAL1 (pin 19) → Crystal → XTAL2 (pin 18) → Crystal (with 30pF caps to GND)
- RST (pin 9) → 10K to VCC, 10μF to GND
- EA (pin 31) → VCC (use internal flash)
Keil μVision Setup
Keil μVision is the standard IDE for 8051 development in Indian colleges:
- Download Keil MDK (free for 8051, limited code size) from keil.com
- Install the C51 compiler package
- Create New Project → Select AT89S52 from Atmel device list
- Add new source file (.c or .asm)
- Set crystal frequency to 11059200 Hz in project options
- Build → produces .hex file for programming
Free alternative: SDCC (Small Device C Compiler) — open source, works on Linux/macOS/Windows. No IDE but produces standard Intel HEX output.
First Program: LED Blink
// AT89S52 LED Blink - C language (Keil C51)
#include <reg52.h>
sbit LED = P1^0; // LED connected to Port 1, bit 0
void delay_ms(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++)
for (j = 0; j < 115; j++);
// Approximately 1ms at 11.0592 MHz
}
void main() {
while (1) {
LED = 0; // LED ON (active low if common anode)
delay_ms(500);
LED = 1; // LED OFF
delay_ms(500);
}
}
// Assembly version (for assembly language lab)
; LED Blink in 8051 Assembly
ORG 0000H
MAIN:
CLR P1.0 ; Clear bit 0 of P1 (LED ON)
ACALL DELAY ; Call delay subroutine
SETB P1.0 ; Set bit 0 of P1 (LED OFF)
ACALL DELAY
SJMP MAIN ; Loop forever
DELAY:
MOV R0, #200 ; Outer loop counter
L1: MOV R1, #250 ; Inner loop counter
L2: DJNZ R1, L2 ; Decrement R1, jump if not zero
DJNZ R0, L1 ; Decrement R0, jump if not zero
RET
END
Understanding 8051 Ports and I/O
8051 has four 8-bit I/O ports (P0, P1, P2, P3), each with specific characteristics:
- Port 0 (P0): Open-drain — needs external 10K pull-up resistors for output. Also used as data bus when accessing external memory.
- Port 1 (P1): General-purpose I/O with internal pull-ups. Best choice for simple LED/button projects.
- Port 2 (P2): I/O with pull-ups, also address bus [A8-A15] for external memory.
- Port 3 (P3): I/O with pull-ups, has alternate functions: RXD(P3.0), TXD(P3.1), INT0(P3.2), INT1(P3.3), T0(P3.4), T1(P3.5), WR(P3.6), RD(P3.7).
// Reading a button and controlling LED
#include <reg52.h>
sbit LED = P1^0; // LED on P1.0
sbit BUTTON = P3^2; // Button on P3.2 (INT0 pin)
void main() {
LED = 1; // LED off initially
BUTTON = 1; // Set as input (port pin high)
while (1) {
if (BUTTON == 0) { // Button pressed (active low)
LED = 0; // LED on
} else {
LED = 1; // LED off
}
}
}
Timers and Interrupts
// Timer0 interrupt for 1-second blink at 11.0592 MHz
#include <reg52.h>
sbit LED = P1^0;
unsigned char count = 0;
void timer0_isr() interrupt 1 {
// Called every 50ms (Timer0 overflow)
TH0 = 0x3C; // Reload for 50ms
TL0 = 0xB0;
count++;
if (count >= 20) { // 20 × 50ms = 1 second
LED = ~LED; // Toggle LED
count = 0;
}
}
void main() {
// Timer0, Mode1 (16-bit)
TMOD = 0x01;
TH0 = 0x3C; // For 50ms with 11.0592 MHz crystal
TL0 = 0xB0;
ET0 = 1; // Enable Timer0 interrupt
EA = 1; // Enable global interrupts
TR0 = 1; // Start Timer0
while (1) { /* Main loop - ISR handles LED */ }
}
Frequently Asked Questions
Why is 11.0592 MHz the standard crystal frequency for 8051 in India?
11.0592 MHz produces exact baud rate timing for standard serial communication (9600, 19200, 115200 bps) without errors. Other crystal frequencies (12 MHz, 24 MHz) produce fractional baud rates with errors. Indian college labs almost universally use 11.0592 MHz crystals for this reason.
Can I use Arduino IDE with AT89S52?
No — Arduino IDE doesn’t support the 8051 architecture. Use Keil μVision (Windows), SDCC (cross-platform), or Keil’s online compiler. Many Indian students also use Proteus ISIS for simulation before programming the actual chip.
What is the difference between 8051 and AT89S52?
The 8051 is Intel’s original architecture specification. AT89S52 is Atmel’s (now Microchip) implementation with improvements: 8KB flash (vs 4KB in original 8051), ISP programming capability via SPI (no UV erasure needed), and enhanced timers. It is fully 8051-instruction-set compatible.
How do I simulate AT89S52 programs before burning?
Proteus ISIS (professional simulator) is widely used in Indian college labs and supports AT89S52 with virtual LEDs, LCDs, keyboards, and other peripherals. The free version has limitations but is sufficient for lab experiments. Keil μVision also includes a software simulator.
What are common 8051 projects for BE/BTech final year in India?
Popular projects include: electronic voting machine, stepper motor speed controller, LCD-based calculator, temperature monitoring with DS18B20, RFID attendance system, and traffic light controller. These align with VTU/JNTU syllabus requirements and are commonly requested by lab examiners.
Add comment