Blinking Led using 8051 (AT89S52) with video tutorial full explanation for beginners

A small intro,

Hello World :) ,
Yes, I am saying hello to the embedded programming world by this linking led aka blinky led. In every programming platform like java, c, c++ we will use the hello world programming (printing hello world using printf statement). In embedded programming instead of printing some texts (say hello world) we may vary the output pin from high(1 or 0xFF) to low(0 or 0x00).

In normal programming printing some texts with logic and doing some front-end and back-end is matter so we call printf as a hello world program. In case of embedded programming world controlling the input and output pins and interfacing with devices, sending data and so on matters much. So we call this blinking ed or blink led as a Hello world program.

Before You should know the followings 

Have a look into the hardware,

We are going to use 8051 AT89S52 micro-controller. We know and this micro-controller's input/output ports from datasheet. To blink the LED, that led should be connected to any one of the i/o pin through a resistor.

We can connect either anode (+) or cathode (-) side of LED to the output pin we are going to use. If we connect anode (+) to op pin writing 1 or 0xFF will glow or light the LED. In other cathode (-) side is connected to micro-controller writing 0 or 0x00 will glow or light the LED. To unlight the LED's do the reverse for both anode, cathode.

We are going to use the 8051 Development

ISP Programmer


Blinking LED Program

void delay() {
    int i,j;
    for(i=0;i<1000;i++) {
        for(j=0;j<100;j++) {

void main() {
    P1_0 = 0;
    while(1) {
        P1_0 = 1;
        P1_0 = 0;



This includes the header file at89x52.h. It contains the meaning of  pins like P1_0,P1,P2,etc..,
You can view this header and you can which pin linked to which memory.

delay() function

First two integers are initialized by int i,j.
Here is the delay function logic starts. We know the logic of for loop. So we are doing some delay by increasing the i value for 1000 times so j is increases 100*1000 times. It will do some small delay as nothing is processed inside the for loop.

main() function   

In this main function only the program starts.
P1_0 denotes pin number 1 and by assigning this to 0, we are making the LED to be in off stage. Then it entes the infinite loop called while(1). By assigning P1_0 = 1 we are making the LED to glow. Then we will call the delay function. so LED will glow upto the execution of delay function. After some delay we will make the LED to be in off stage and we again call delay so that we are making this LED to be in off stage upto the execution of delay function. This executes infinite times or upto the micro-controller is powered.

What if i get chip enable error in progisp
What is the logic for blinking multiple LED

Video Tutorial:

-> Let Us Embed <-