LEDs one by one ON

Display on the LEDs connected to port the pattern as explained:

  • First, all the LEDs should be off and remaining in this state for about 1 sec.
  •  After 1-second laps  switch on the only LED0(bit 0)
  •  After 2 seconds laps switch on the only LED1(bit 1)
  •  ………………………………………………………
  •  ………………………………………………………
  •  After 8 seconds laps switch on the only LED7(bit 7)
  •  Switch of all the LEDs for about 3 secs.

Required components

  • 8051 MCU
  • 8 LED
  • 8 Registers 330 ohm
  • Jumpers

Circuit diagram

LEDsatP2_turnOn

8 RED LEDs are connected to port 2. The cathode of each LED is connected to the Ground. The Anode of each LED is connected to port pins.  The resistor is needed to limit the flow of current.

As the cathode of LED is connected to the Ground terminal, we just need to provide a positive voltage to LED`s Anode terminal. So in order to turn on the LED we just need to give HIGH logic (1) to the port pin(where LED is connected).

Code

Code description

To turn the LED one by one, I am just setting a bit at a time, and assigned that value to port2.

Iteration1(1 << 0):

0000 0001 Turn ON LED0.

Iteration1(1 << 1):

0000 0010 Turn ON LED1.

Iteration1(1 << 2):

0000 0100 Turn ON LED2.

Iteration1(1 << 3):

0000 1000 Turn ON LED3.

Iteration1(1 << 4):

0001 0000 Turn ON LED4.

Iteration1(1 << 5):

0010 0000 Turn ON LED0.

Iteration1(1 << 6):

0100 0000 Turn ON LED6.

Iteration1(1 << 7):

1000 0000 Turn ON LED7.

Lastly, 0x00 will make all led to off, delay_ms(3000) will provide a delay of 3  seconds.

LEDs will turn one by one 5 times and then it will stop.

Download Proteus Circuit and Hex File

Video

Thank you for reading…

Leave a Comment

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