Flash Single LED by Complement Logic

Flash an LED connected to the port line using complement logic at the rate of 1 second for 10 times and stop.

Description

Here we need to connect LED at one of the port pins, toggle it 10 times, which means we have to turn it ON, wait for 1 second and turn it off. After toggling for 10 times it should turn off, now the LED will turn ON only on resetting MCU.

Recommended: If you haven`t go through the previous post, please go and check it where I have shown some of the ways to connect the LEDs to the Micro-controller port pin.

Required components

  • 8051 MCU
  • LED
  • Register 330 ohm
  • Jumpers

Circuit diagram

Led_atP2_0_Toggle_by_complement_logic

A single RED LED is connected. Anode of LED is connected to Pin no 21 through Resister. Cathode of LED is connected to Ground, Resistor is needed to limit the flow of current.

As the Cathode of LED is connected to ground, we just need to provide High(Logic 1) to LED Anode terminal to turn it ON.

Code

Header files required:- delay.h

Download it from here

Code description

As to toggle LED we need to turn it ON and again turn it OFF. To blink for 10 times we need to complement bit for 20 times. 1st time for turning it ON and 2nd time to turn it OFF.

At line 11 port 2 was initialized with 0x00 by instruction P2 = 0x00.

1st iteration

Now P2 = P2 ^ 1;  Will do

0000 0000 X-ORing with

0000 0001

X-OR: 1 for dissimilar input and 0 for similar input so

P2  = 0000 0001 which means 1 to pin2.0 where LED is connected which will turn ON the LED.

delay_ms(1000); will provide delay 1000 milliseconds(1 second).

Now in the second iteration

0000 0001 X-Oring with

0000 0001

will results in 0000 0000 which means 0 to all pins of port 2 which will turn OFF the LED connected at pin2.0.

The cycle repeats 10 times and stops.

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 *