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

Leave a Reply

34 Comments on "LED Blinking using 8051 Microcontroller and Keil C – AT89C51"

avatar
  Subscribe  
newest oldest most voted
Notify of
ASequeira
Guest

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

Ligo George
Guest

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

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

Target Tab..

Mr Raja
Guest

you can use 12Mhz crystal…

kamal
Guest
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… Read more »
Ligo George
Guest

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

kamal
Guest
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… Read more »
Ligo George
Guest

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

Pawel
Guest

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

krishna
Guest

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

pranablhkr
Guest

can i use 89s51 instead of 89c51

gayathri
Guest

crystal oscillator frequency for AT89C51 is 11.0592Mhz

shedy
Guest

11.0592mhz

Mohamed Patel
Guest

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

Ligo George
Guest

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

gourab
Guest

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

ghanshyam
Guest

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

Ligo George
Guest

You need an 8051 IC programmer for that.

taufixtakahashi
Guest

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

Taher Ujjainwala
Guest

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

Ligo George
Guest

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.

umar
Guest

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

Panduranga N M
Guest

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

Ligo George
Guest

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

Ligo George
Guest

Sorry, I don’t get you.

aradhaya
Guest

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

Ligo George
Guest

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

GANESH RAMACHANDRAN
Guest

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

Sriram Chandrabhatta
Guest

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?

Ligo George
Guest

Yes, it should.

Nipun Soni
Guest

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

Ligo George
Guest

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

Chandra Shekhar
Guest

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

Xen NiXus
Guest

11.0592mhz

Sourav Sunny
Guest

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