Control of 2 LEDs with a Single Push Button using AT89C2051 Microcontroller
Pins Diagram:
In this tutorial, I'll show you how to control 2 LEDs with a single pudh button. When the button is on, one LED is then turn on, and when the button off, another LED is turn on. Here, I connected LEDs in Sourcing mode.
Proteus Circuit Diagram Code
//Code by Shahid Khan
//Control of 2 LEDs with a Single Push Button
#include
#include
sbit REDLED = P3^1;
sbit GREENLED = P3^0;
sbit PB1 = P3^4;
void main()
{ REDLED = 0;
GREENLED = 0;
PB1 = 1;
if (PB1==1)
{
REDLED = 1;
}
else
{
GREENLED = 1;
}
}
Simulation Video
Proteus Circuit Diagram Code
//Code by Shahid Khan
//Control of 2 LEDs with a Single Push Button
#include
#include
sbit REDLED = P3^1;
sbit GREENLED = P3^0;
sbit PB1 = P3^4;
void main()
{ REDLED = 0;
GREENLED = 0;
PB1 = 1;
if (PB1==1)
{
REDLED = 1;
}
else
{
GREENLED = 1;
}
}
Simulation Video
Post a Comment