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.

AT89C51
AT89C51

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
untitled
3. Create a new Project : Project >> Create µVision Project
untitled
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
untitled
Right click on Target1>>options for target “target 1”
In the Output Tab check the “Create HEX file” box<
untitled


  • 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
        Delay();
        LED = 1;            // LED OFF
        Delay();
    }
}

void Delay(void)
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

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

  • Please help me to write the program of this question using microcontroller 8051myb

    When the key INT0(P32) is pressed down,realize counter automatically add one and 8 digits counter. (000,001,010,011,100,101,110,111,000,……).(you can use D2,D3 AND D4)

    My email:[email protected]

  • 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

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

  • 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?

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

  • 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

  • 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.

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

  • 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

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

  • 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!!

  • 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..

  • 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.

  • 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..

  • 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.

    thanks


  • >