Blinking LED using 8051

admin June 5, 2012 6 Comments

Blinking 1 LED using 8051

This is the first project regarding 8051 and of course one of the simplest, blinking LED using 8051. The microcontroller used here is AT89S51 In the circuit, push button switch S1, capacitor C3 and resistor R3 forms the reset circuitry. When S1 is pressed, voltage at the reset pin (pin9) goes high and this resets the chip. C1, C2 and X1 are related to the on chip oscillator which produces the required clock frequency. P1.0 (pin1) is selected as the output pin. When P1.o goes high the transistor Q1 is forward biased and LED goes ON. When P1.0 goes low the transistor goes to cut off and the LED extinguishes. The transistor driver circuit for the LED can be avoided and the LED can be connected directly to the P1.0 pin with a series current limiting resistor(~1K).  The time for which P1.o goes high and low (time period of the LED)  is determined by the program. The circuit diagram for blinking 1 LED is shown below.

blinking one led 8051

Blinking  LED using 8051

Program.

START: CPL P1.0
       ACALL WAIT  
       SJMP START

WAIT:  MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
        DJNZ R3,WAIT2
        DJNZ R4,WAIT1
        RET

Blinking  2 LED alternatively using 8051.

This circuit can blink two LEDs alternatively. P1.0 and P1.1 are assigned as the outputs. When P1.0 goes high P1.0 goes low and vice versa and the LEDs follow the state of  the corresponding port to which it is connected. Here there is no driver stage for the LEDs and they are connected directly to the corresponding ports through  series current limiting resistors (R1 & R2). Circuit diagram is shown below. 

blinking 2 led alternatively 8051

Blinking 2 LED alternatively using 8051


Program.

START: CPL P1.0
       ACALL WAIT  
       CPL P1.0
       CPL P1.1
       ACALL WAIT
       CPL P1.1  
       SJMP START

WAIT:  MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
        DJNZ R3,WAIT2
        DJNZ R4,WAIT1
        RET

Testing images and videos.

Comments
  • r3tr0
    August 11, 2014

    When I assemble the circuit there is a slight problem .

    When I press the switch it turns off
    When I’m not pressing it turns on.
    Can anyone follow up ?

  • eyasu
    February 6, 2014

    can you help me this project by using micro c and circuit diagram

    Develop a system in 8086 to Blink an LED in following order based on key press.
    (a) Key pressed=>Blink LED alternate (b)Key not pressed=>Blink LED

  • Stephen
    September 20, 2012

    Why is it that when i tried to run the blinking 1 led program in a simulator the led didnt blink but rather just remained on?

    • jojo
      September 20, 2012

      @stephen – You may verify the program once again. Please ensure it is correct. The problem may be with your delay routine. The delay should be significant for human eyes. Try making it around 1/2 second or more.

  • Seetharaman
    May 11, 2012

    Hi Mark here the current requirement is <10mA, hence BC548 is good enough, if you still feel a better switching transistor will be useful here, you can sustiute with 2N2222

  • May 10, 2012

    BC548 is a really bad transistor. It has low maximum power and maximum current limits. Should have used an 2N2222 or a MOSFET.

Leave a Reply

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