NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

How to Blink an LED using 8051


In the project we are going to see how an led is interface to an 8051 microcontroller.
1)      Design of Circuit diagram and  explanation using proteus tool.
2)      Writing 8051 assembly code to glow an LED in Microvison keil IDE tool
3)      Writing embedded c code to glow an LED in Microvison keil IDE tool.
4)      Simulating both programs using proteus tool.
Design constraints of Circuit
When we are connecting an load(LED) to source(Microcontroller Port), first of we need to know
1)      What voltage is required for an LED to ON.                                           Ans: 2V-3V
2)      What current is required for an LED to glow brightly enough.       Ans: 10ma(dim) – 50ma(bright)
3)      Is microcontroller providing sufficient voltage and current to an LED.      
Ans:  8051 microcontroller port voltage for logic high is 2.4V-5V(Voh) and for logic low is
0V-0.45V(Vol).
          Current it provides -60 micro amps(sourcing)  and 1.6mA (sinking current).
   
8051 microcontroller voltage and current ratings.                 

What are Iol and Ioh?
Iol means Current Output Low : “ refers to the digital output circuit current sinking capability”.
Ioh means Current Output High:“ refers to the current sourcing or supplying capability”.
What are Vol and Voh?
Voh means Voltage Output: refers to the minimum output high voltage of the device.
Vol  means Volatge Output: refers to the maximum output low voltage of the device.



If we connect Led directly to port as shown below fig1.1. Direct 5v of the port is applied to an LED, so that LED may damaged or we already found that port driving current is 60microamos is not sufficient to drive an LED(Slightly glow).

To solve this problem, we connect the LED between port and Vcc as shown in Fig 1.2. Because the current sinking value is 1.6 mili amps. This current is sufficient to glow an LED and this current is sourced by vcc and sinked by microcontroller port.


If we connect the led as above, led will glow for very small time with high brightness and burn out. Because large current  will be sink via LED from source due to high vcc voltage. Some times this large current may damage 8051 port and then IC. To limit the current allowed into LED we need to divide the voltage by adding a resistor to the circuit.
If we want to allow 20mA current through the LED the resistor value will be
R1 = (Vcc-led voltage)/current.
R1 = (5-2)/20mA.
R1= 150 Ohms.


















Circuit Diagram developed in Proteus




In this diagram I connected a 100 ohms resistor to allow 30mA current through the LED. Now LED glow more brightly than in previous case (for 20mA).
The heart of the microcontroller is clock, without the clock the microcontroller will not run. Hence a Crystal clock of 12MHz is connected between two pins Xtal1 and Xtal2 along with two 33pf capacitors as shown in fig 1.4.
Why Pico faraday capacitance is connected? Why not micro faraday?
Generally for smaller values of capacitance is preferred for higher frequencies. Capacitance(C) is inversely proportional to frequency (f). For higher frequencies the charging and discharging of capacitor is very fast, so that smaller values of capacitance is preferred.

Program To Blink an led in Assembly Language
org 0000h
                mov P2,#00h  ; initialize the Port2 as output port
top:          cpl P2.0    ; compliment the bit
                acall delay           ; call delay procedure   
                sjmp top              ; make this operation to run repeatedly

delay:
                 mov R1,#010h  ; initialize the R1 register with an immediate value 10h = 16d
                 mov R0,#0FFh  ; load R0 with FFh value to repeat the loop for 256 times
back:         DJNZ R0, back   ;internal loop repeates 256 times
                 DJNZ R1,back    ;external loop repeates 16 times
                 RET
End

Program To Blink an led in c

#include
sbit LED = P2^0;  // define Port2 pin as an LED
void delay(int);

void main()
{
 while(1)  // infinite loop
 {
                LED = ~LED;  // toggle LED
                delay(10000);
 }// end of while loop


} // end of main

void delay(int i)
{
for(;i>0;i--);
}


Download the Document

8 comments :

  1. i like this blog . this is amazing blog .thanks for share info, www.liveurlifehere.com/Blog, amanyadav007.blogspot.com

    ReplyDelete
    Replies
    1. hello dear to all
      can u tell me?
      i have 5volt/1amp smps power supply. can i use it as vcc?
      can i directly apply to the port of vcc and gnd?

      Delete
  2. The Intel MCS-51 (commonly referred to as 8051) is a Harvard architecture, single chip microcontroller (µC) series which was developed by Intel in 1980 for use in embedded systems.microcontroller 8051.

    ReplyDelete
  3. This was a good suggestion that you put up here...dude…..hope that it benefits all the ones who land up here. 
    Electrical Wholesalers

    ReplyDelete
  4. hello. can you tell me how to blink the same setup of led only 10 times and stop?

    ReplyDelete
    Replies
    1. Sorry for the late reply!
      you replace the code
      while(1) // infinite loop
      {
      LED = ~LED; // toggle LED
      delay(10000);
      }// end of while loop

      with the following code

      while(1) // infinite loop
      {
      for(i=0;i<10;i++)
      {

      LED = ~LED; // toggle LED
      delay(10000);
      }
      while(1);

      }// end of while loop

      Delete
  5. Barbecue beef brisket is the national dish of the Republic of Texas. Here's the recipe for how to cook it the way the BBQ champions abd BBQ restaurants cook it. Learn how to grill Brisket steak in best weather now!

    ReplyDelete

Thanks for visiting NPEDUCATIONS. We will contact you soon

8 comments :

Aman yadav said...

i like this blog . this is amazing blog .thanks for share info, www.liveurlifehere.com/Blog, amanyadav007.blogspot.com

rogwil said...

Thank u Aman yadav!

manoj singh said...

The Intel MCS-51 (commonly referred to as 8051) is a Harvard architecture, single chip microcontroller (µC) series which was developed by Intel in 1980 for use in embedded systems.microcontroller 8051.

Urooj Shah said...

This was a good suggestion that you put up here...dude…..hope that it benefits all the ones who land up here. 
Electrical Wholesalers

Yadav Arjun said...

hello dear to all
can u tell me?
i have 5volt/1amp smps power supply. can i use it as vcc?
can i directly apply to the port of vcc and gnd?

manish said...

hello. can you tell me how to blink the same setup of led only 10 times and stop?

Lovakiranvarma Myla said...

Sorry for the late reply!
you replace the code
while(1) // infinite loop
{
LED = ~LED; // toggle LED
delay(10000);
}// end of while loop

with the following code

while(1) // infinite loop
{
for(i=0;i<10;i++)
{

LED = ~LED; // toggle LED
delay(10000);
}
while(1);

}// end of while loop

pack rat extermination tucson said...

Barbecue beef brisket is the national dish of the Republic of Texas. Here's the recipe for how to cook it the way the BBQ champions abd BBQ restaurants cook it. Learn how to grill Brisket steak in best weather now!

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger