Blink LED with single push button using 8051 AT89S52 self learning developer kit - Video tutorial

In this tutorial We are going to use a single push button. When it is first pressed LED will be turned ON. When it is pressed next LED will be turned off.
How to turn on and off LED with 2 push buttons?

Hardware Connection:

The i/o connections are,


P0_0 to Gnd, +5 to SW1


P1_0 to LED


void main() {
P0_0 = 0;
P1_0 = 0;
while(1) {
if(P0_0 == 1) {
while(P0_0 != 0);
P1_0 = ~ P1_0;


P0_0 for input i.e push button.
P1_0 for output i.e LED.

Inside the super loop, 

if P0_0 is equal to 0 aka push button is pressed toggle the led state. So if the LED is Off then turn On the LED and vice versa.

while(P0_0 != 0) 

It is added for debounce. This is a software debounce it simply means waiting for push button to release.

How to turn on and off LED with 2 push buttons?

Working Video:

Will be available soon!! :)

-> Let Us Embed <-