SOFTWARE: KEIL MICRO VISION 4
SIMULATOR: PROTEUS 8.0
CIRCUIT DIAGRAM:
CIRCUIT WORKING:
Led's 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 does 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 led's I have provided 0V(logic 0)and for turning OFF the led's 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 led's 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 led's will get turned ON otherwise they are remained in the OFF state.
Comments