Skip to main content

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​

Software​

  • Keil uVision (C51)
  • Programmer tool/software for USBasp (whatever you use for AT89S52 flashing)

2) Check Jumper (JP3)​

  1. Power OFF the board.
  2. Locate the JP3 jumper (LED jumper).
  3. Ensure JP3 is connected.
  4. Power ON the board.

3) Create a New Project in Keil uVision​

  1. Open Keil uVision
  2. Go to Project → New uVision Project...
  3. Create a folder (example: AT89S52_LED_Blink) and save the project.
  4. Select the device: Atmel → AT89S52
  5. When asked to add startup code, click Yes.

4) Add a C File (main.c)​

  1. In the Project panel, right click Source Group 1
  2. Click Add New Item to Group...
  3. Select C File (.c)
  4. Name it: main.c
  5. Paste the code below.

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
}
}