LED Blinking using 8051 Microcontroller and Keil C – AT89C51

LED Blinking using 8051 Microcontroller and Keil C – AT89C51

8051 Microcontroller is a programmable device which is used for controlling purpose.
Basically 8051 controller is Mask programmable means it will programmed at the time of manufacturing and will not programmed again, there is a derivative of 8051 microcontroller, 89c51 micro controller which is re-programmable.



89c51 is 8-bit device means it is capable of doing 8-bit operations.  It have 4 ports which are used as input or output according to your need.
This device also have Timer, Serial Port interface and Interrupt controlling you can use these according to your need. The datasheet may be downloaded from here.

8051 Ports Explained

8051 Port in Output Mode

8051 Port in Output Mode

8051 Port in Input Mode

8051 Port in Input Mode

Using Keil uVision 4

1. Download and Install Keil uVision4

2. Open Keil uVision
3. Create a new Project : Project >> Create µVision Project
4. Browse for the location
5. Select the microcontroller Atmel>>AT89C51
6. Don’t Add The 8051 startup code
7. File>>New
8. Adding Hex file to the output
Right click on Target1>>options for target “target 1”
In the Output Tab check the “Create HEX file” box<

  • To change the operating frequency goto Target tab on the window obtained by right clicking on Target1>>options for target “target 1”

Circuit Diagram

LED Blinking with 8051 Microcontroller - AT89C51

LED Blinking with 8051 Microcontroller – AT89C51

Keil C Program

#include<reg52.h>           // special function register declarations
                            // for the intended 8051 derivative

sbit LED = P2^0;            // Defining LED pin

void Delay(void);           // Function prototype declaration

void main (void)
    while(1)                // infinite loop
        LED = 0;            // LED ON
        LED = 1;            // LED OFF

void Delay(void)
    int j;
    int i;

1. Enter the  source code.

2. Save it

3. Then Compile it. Click Project>>Build Target or F7

The hex file will be generated in your Project Folder.

AT89C51 needs an oscillator for its clock generation, so we should connect external oscillator. Two 22pF capacitors are used to stabilize the operation of the Crystal Oscillator. EA should be strapped to VCC for internal program executions. AT89C51 has no internal Power On Reset, so we have to do it externally through the RST pin using Capacitor and Resistor. When the power is switched ON, voltage across capacitor will be zero, thus voltage across resistor will be 5V and reset occurs. As the capacitor charges voltage across the resistor gradually reduces to zero.

This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming, for parts that require
12-volt VPP.

The circuit may be simulated using Proteus. If you haven’t yet started with Proteus, please go through this tutorial. You can buy Proteus from Labcenter Electronics.

Download Here

You can the entire Keil C project files here.

Share this post

Comments (36)

  • ASequeira

    Hello sir…I have a question….what is the value of the crystal in the circuit?

    September 2, 2013 at 8:14 pm
  • Ligo George

    Use the crystal with frequency given in your Keil C settings..

    Right Click on Target1>>options for target “target 1″

    Target Tab..

    September 3, 2013 at 7:10 am
  • Mr Raja

    you can use 12Mhz crystal…

    October 23, 2013 at 11:53 am
  • kamal

    hi there. I have a atmel programming kit for AT89C51. This has the interface “CP2102 USB to UART master controller” to communicate with the computer. I have no problem with IDE. Now I want to fuse the “hex” file in to my controller. I searched in the net and found driver for my programmer interface (USB to UART). So the interface communicaiton has no problem. Now I need a utility to fuse the program in to MC. Could you please suggest me a good utility with download url to fuse programs in my AT89C51? It will be so helpful to me.


    November 26, 2013 at 12:13 pm
  • Ligo George

    I don’t get what you are trying to convey…
    I think you need to program AT89C51 with your development board.. Am I right??
    If so… it should automatically program your microcontroller when you use your development board….. I hope that you needn’t any extra drivers..

    November 26, 2013 at 1:40 pm
  • kamal

    Thanks for the reply. yes you are correct. But actually I don’t need drivers, coz I already found it. This I have stated very clearly in my previous post. All I need is a tool/utility to fuse my hex file in to my AT89C51. Let me make it clear. For example, I have been using phillips P89V51RD2 before this. It has an ISP. So my burn setup will have an MC with serial (MAX232) system connected board. And I use PL2302 usb to serial converter so that I can connect my MC board serial port to system usb port. so I have to use PL2302 driver installed on my sys and thru “Flash magic” I could burn my hex thing to MC IC. In this case, it has no ISP thing like phillipse. So I need a programmer kit. This programmer kit has in build “CP2102 USB to UART bridge controller” and thus it demands a driver. That, I already installed it. But I have to have a fuse program to push the hex file from system to controller IC. Thats all. Correct me if I am wrong. After buying the Atmel programmer kit, in home only I came to realise that the program CD is damaged. So, I need help.

    November 26, 2013 at 2:42 pm
  • Ligo George

    The programmer software will depend on the programmer you are using…
    Which is the programmer you are using??
    Google the programmer name or serial number… you can find the utility software..

    November 26, 2013 at 5:06 pm
  • Pawel

    What is the frequency of that blinking LEDs and haw to change it?

    February 3, 2014 at 5:26 am
  • krishna

    Sir,how to program this AT89C51 sir….by using what device?

    February 4, 2014 at 8:15 pm
  • pranablhkr

    can i use 89s51 instead of 89c51

    March 12, 2014 at 2:59 pm
  • gayathri

    crystal oscillator frequency for AT89C51 is 11.0592Mhz

    July 16, 2014 at 8:44 pm
  • shedy


    December 8, 2014 at 9:45 am
  • Mohamed Patel

    Hellow sir,

    Am working on project named phase angle measurment using 8051 MC… in this am taking current and voltage waveform from ct and pt and giving them to ZCD to convert them into a square wave … my logic is when the voltage wave goes in timer is on and when the current wave goes in the timer is off and the difference between them is phase angle which i want to display … can you give me a programme of this in 8051 MC?

    Thank you!!

    March 12, 2015 at 11:59 am
  • Ligo George

    Please use our forums (https://electrosome.com/forums/) for posting doubts not related to above article.

    March 17, 2015 at 4:54 pm
  • gourab

    please do someone get me details regarding density based traffic control system usin ir sensor and at89c51 microcontroller… do email me: [email protected]

    April 13, 2015 at 12:06 am
  • ghanshyam

    how to load the hex file in the controller,means what kind of hardware is required.Will it work simply with RS 9 pin??

    June 29, 2015 at 4:20 pm
  • Ligo George

    You need an 8051 IC programmer for that.

    July 1, 2015 at 7:30 pm
  • taufixtakahashi

    I have a question, im interfacing 8051 with led blinking using button pressed. I included a reset button. When i pressed button led start blinking. But may i know how my reset button is working ? Thankyou

    August 20, 2015 at 8:11 am
  • Taher Ujjainwala

    your reset button is working but by default the led will blink the previous program which is been fed into it before sometime

    September 21, 2015 at 8:46 pm
  • Ligo George

    Just implement a long pattern of LED blinking with different timings and try reset button. You can see that the pattern is starting from the beginning when the reset button is pressed.

    October 3, 2015 at 1:06 pm
  • umar

    Hy sir actually i made a simple micro based controlled led ckt. In software( uvision 3) i can enter the code and saved it. but after saving the programme when i can click the build target or F7 an error accourd in the programme and programme cannot be run. so can u help me to build this one. thanks

    October 18, 2015 at 9:00 pm
  • Panduranga N M

    hi der after debugging it is not showing blinking in port.

    November 7, 2015 at 8:20 pm
  • Ligo George

    I think you didn’t add the source file to the project.

    November 21, 2015 at 1:44 pm
  • Ligo George

    Sorry, I don’t get you.

    November 21, 2015 at 2:10 pm
  • aradhaya

    can anyone plz tell me the code to print any alphabet on led port

    January 11, 2016 at 6:19 pm
  • Ligo George

    Sorry, I don’t understand your question. printing alphabet on led port ??

    January 24, 2016 at 12:46 pm

    Can u write a code for blinking led in Kinetis Design studio IDE for MKE02ZVLD2 controller ?

    February 11, 2016 at 9:25 am
  • Sriram Chandrabhatta

    Sir will this program work for any ATMEL variant of C51 i.e., say if the variant is AT89C51ED2, will this program work in that variant?

    September 19, 2016 at 4:06 am
  • Ligo George

    Yes, it should.

    September 22, 2016 at 7:29 pm
  • Nipun Soni

    the tick in the 0th position of P0 of parallal port 0 blinks.. it isn’t blinking! 🙁

    September 24, 2016 at 1:55 pm
  • Ligo George

    It means that you have some problems in proteus connections. Check the resistor value also.

    November 27, 2016 at 12:43 pm
  • Chandra Shekhar

    Hi sir, can you plz provide the link to download proteus software for windows 7 64 bit system

    April 4, 2017 at 10:01 am
  • Xen NiXus


    April 12, 2017 at 5:41 am
  • Sourav Sunny

    sir, i need explanation about above article ie.., how the led blinking? ,how the data flows?
    im doing on the project named “micro controller based over current relay” in stead of relay im using led. is above article will work for my project or not? if yes, please explain

    November 5, 2017 at 2:20 pm

    Sir if i have to blink two LEDs in particular port then how i can??

    June 8, 2018 at 11:42 am
  • Shyna Kamboj

    11.0592 mhz

    July 27, 2018 at 6:39 pm

Leave a Reply

Your email address will not be published. Required fields are marked *