The first “Hello World!” project I prefer for Microcontroller is LED Blinking. I have used ATMEL’s 89C51 (40-pins DIP) 8051 architecture microcontroller which is ideal for first time learning MCU Chip.  The program is very simple and straight forward, that uses a delay procedure  loop based software delay.

Source Code

Here,i have  written code  in C using Keil uVision4.

#include <REGX51.H>
void msdelay(unsigned int );
void main(){

P2=0×00;  //all pin of PORT2 declared as output
//infinite loop
while(1){

P2=0xFF;   //all pin high
msdelay(250);    //delay
P2=0×00;   //all pin low
msdelay(250); //delay

}
}

//delay function
void msdelay(unsigned int value){

unsigned int x,y;
for(x=0;x<value;x++)
for(y=0;y<1275;y++);
}

In C programs you cannot be sure of delay, cause  it depends on compiler how it optimize the loops as soon as you make changes in the options the delay changes.

you will have to use Timers for making exact delays….. it does not matters whether u need delays of ms , us or even seconds…

below is a function of 1 second using timers…..

// the idea is to make a 50ms delay and run it 20 times as 20x50ms= 1000ms= 1sec

delay_1s() // timer of 1 sec
{
int d;
for(d=0;d<=20;d++)
{
TMOD=0×01;
TL0=0xFD;
TH0=0x04B;
TR0=1; // start timer.
while(TF0==0); // run until TF turns to 1
TR0=0; // stop timer
TF0=0; // reset the flag
}
}

Circuit Diagram

Led blinking with 8051 microcontroller

About these ads

Comments on: "Led blinking program with 8051 Microcontroller and Keil uVision4" (50)

  1. Fazla Mehrab said:

    Nice post. Very much helpful for a beginner in 8051.
    Keep going. Happy blogging.

  2. Mantoo Kaibarta said:

    very nice program for beginers……….thanks…

  3. NANDHINI said:

    thank you soo…. much for this program. I’m the beginner of 8051 programming. keep posting more…….

  4. can i use Keil u vision and STK 500.

  5. Anonymous said:

    how i can program micro controller to delay for one minute using assembly language.

  6. thanks bro am the begginer microntroller programming ,

  7. chinmaya ranjan sethi said:

    i want make a indurance pannel so sir i want make a logic gate of Xor gate condition of port p0.1 and p1.0,and thats out put time interval should be same as interms of mili sec
    .so kindly send me it plz..

  8. p. jaya sekhar said:

    what is the crystal frequency?

  9. pls help me to learn uvision 4 by keil

  10. pls help me out

  11. Diwakar Rajput said:

    how can program AT89C2051 using serial port (DB9).

  12. Anonymous said:

    L.E.D ATMEL 89S52 KO LOD KARNA KA PAROGRM

  13. hello i did a project for blinking led its working but the output is very low wat may be the problem please help me…the led blinks with low voltage

  14. Hi. I just bought the pre-assembled 8051 controller, and I know C very well. What I don’t get is, how do I burn the code to the 8051? Everywhere I see tutorials on how to write the code, but how do I get it into the microcontroller so I can see what’s happening? This getting really frustrating. :( Can you please help? Thanks.

  15. manoj kumar said:

    plz tell about the program for “capacitor less ac fan using micro controller”

  16. Neeraj pant said:

    i want to make a let dot matrix moving message display using AT89S52 ….please tell me the circuit diagram and programming schedule

  17. Parshuram said:

    Hi

  18. hi i want to know if i can use these code for STM32F4-Discovery board?

  19. 8051 is very very simple one if any confusion for this 8051 projects conduct my email ID i will help you My email ID:vikefy@gmail.com
    thank you friends

  20. vry vry tanks bro……….

  21. Anonymous said:

    My knowledge says the LED is connection and code is wrong.
    89c51 port can not source (LED glow dim) It can sink well, so connect LED -ve to port pins and other end to +ve via a resistor. When ever port is LOW, the LED glows brighter and if HI, then LED will be off.

  22. ajay patel modasa said:

    nice but put more and more programe for guide us

  23. Anonymous said:

    thnkx for program, nice…………..

  24. thanks…project is working……….

  25. its gd one for learners………………………..thanks

  26. Hafizuddin said:

    I request for permission to use your module and sourcecode as a referral to my education microcontroller lab teaching for beginner since your module is easy to understand. Thank you. =)

  27. Thanks man. Worked beautifully.

    • Anonymous said:

      Just checking if my DP remains the same design and also because I now have a lot of free time.

    • Anonymous said:

      Wow! It’s the same. Nice coding man. Just like I said I have a lot of time.

  28. your programig is nice……..

  29. hiiiiiiii

  30. Kumar Gaurav said:

    This program is not working for 89v51rd2. Can u help me. Thanks in advance

  31. hi this is dominic can any one help me how to flashing 2 windows, which is first fault will come mean the 1 led flash but remaing al all will came 2 led flashing

  32. Anonymous said:

    please if can help me by writing the code for LED to blink alternatively

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 42 other followers

%d bloggers like this: