In this tutorial we are going to turn on the LED when first push button is pressed, turn off the LED when the other push button is pressed. In 8051 AT89S52 self learning developer kit.
P0_1 to Gnd, +5 to SW2
#include<at89x52.h>
void main() {
P0 = 0x00;
P1 = 0;
while(1) {
while(P0_0 == 1) {
P1 = 1;
}
while (P0_1 == 1){
P1 = 0;
}
}
}
P1 port is dedicated for output i.e LED.
First it is set to 0 aka LOW.
Then While(1) aka super loop starts. It has two while loops. They are,
what is super loop ??
Cheers!!!!
-> Let Us Embed <-
Hardware connection
Input
P0_0 to Gnd, +5 to SW1P0_1 to Gnd, +5 to SW2
Output
P1_0 to LEDProgram
#include<at89x52.h>
void main() {
P0 = 0x00;
P1 = 0;
while(1) {
while(P0_0 == 1) {
P1 = 1;
}
while (P0_1 == 1){
P1 = 0;
}
}
}
Explanation:
P0 port is dedicated for input i.e push button.P1 port is dedicated for output i.e LED.
First it is set to 0 aka LOW.
Then While(1) aka super loop starts. It has two while loops. They are,
what is super loop ??
while(P0_0 == 1)
Inside this P1 = 1 is written which means when the first push button is pressed light or turn on the LED.while (P0_1 == 1)
Inside this P1 = 0 is written which means when the first push button is pressed turn off the LED.Working video:
Will be available soon!! :)Cheers!!!!
-> Let Us Embed <-