To control leds through button using 8051 Micro-Controller

SOFTWARE: KEIL MICRO VISION 4


SIMULATOR: PROTEUS 8.0


CIRCUIT DIAGRAM:





CIRCUIT WORKING:


Leds are connected to port 1.0 and port 1.2 pins of port 1.I have used push button which is connected to p3.1.Leds do not get turned ON until the button is pressed.

I have designed this circuit as a current-sinking circuit.So in order to turn ON the leds I have provided 0V(logic 0) and for turning OFF the leds 5V(logic 1) is provided to the respective pins.

If the button(p3.1) is at logic '0' then it is considered as button is pressed.

PROGRAM:


#include<reg51.h>
sbit led1 = P1^0; sbit led2 = P1^2; sbit sw = P3^1;
void main() {
P1=0xfc; // set port 1.0 as output led1=1; // initially turn off the led1 & led2 led2=1;
while(1) //continuous loop {
if(sw==0) // button is pressed {
led1 = 0; // turn on the led1 led2=0; // turn on the led2
}
else { led1=1; //turn off the led1 led2=1; //turn off the led2 }
}
}


PROGRAM DESCRIPTION:


At starting I have kept both the leds off by providing logic '1' to led1 (port1.0) and led2 (port1.2) respectively.After that I have checked whether the button is pressed.If the button is pressed both the leds will get turned ON otherwise they will remain in the OFF state.

VIDEO:



Comments

Popular posts from this blog

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

how to display numbers on lcd?

Introduction of IODIR,PINSEL,IOSET and IOCLR Registers