AT89S52 LED Blink (Keil uVision)
This tutorial explains how to blink the on-board LED on the 8051 Development Board using AT89S52 (8051) and Keil uVision.
✅ Important: The LED is already connected on the development board.
Just make sure the LED jumper JP3 is connected, otherwise the LED will not blink.
LED Connection (On-board)​
On this development board:
- LED is connected to P2.0
- LED is active-LOW
- P2.0 = 0 → LED ON
- P2.0 = 1 → LED OFF
1) Requirements​
Hardware​
- ATMEL AVR 8051 USBasp ISP Programmer
- 8051 Development Board
- USB cable / 5V power (as required by your board)
Software​
- Keil uVision (C51)
- Programmer tool/software for USBasp (whatever you use for AT89S52 flashing)
2) Check Jumper (JP3)​
- Power OFF the board.
- Locate the JP3 jumper (LED jumper).
- Ensure JP3 is connected.
- Power ON the board.
3) Create a New Project in Keil uVision​
- Open Keil uVision
- Go to Project → New uVision Project...
- Create a folder (example:
AT89S52_LED_Blink) and save the project. - Select the device: Atmel → AT89S52
- When asked to add startup code, click Yes.
4) Add a C File (main.c)​
- In the Project panel, right click Source Group 1
- Click Add New Item to Group...
- Select C File (.c)
- Name it:
main.c - Paste the code below.
5) LED Blink Code (Active-LOW on P2.0)​
Note: Delay is approximate and commonly works for basic blinking (timing depends on crystal frequency).
#include <reg52.h>
// On-board LED on P2.0 (active-LOW)
sbit LED = P2^0;
void delay_ms(unsigned int ms)
{
unsigned int i, j;
for(i = 0; i < ms; i++)
for(j = 0; j < 112; j++); // ~1ms delay for 11.0592 MHz (approx)
}
void main(void)
{
LED = 1; // LED OFF (active-LOW)
while(1)
{
LED = 0; // LED ON
delay_ms(500); // 500 ms
LED = 1; // LED OFF
delay_ms(500); // 500 ms
}
}