.
I am connecting push button to the first bit of PORT 0 (P0.0). The LED is connected to the first bit of PORT 2 (P2.0). I am trying to get an LED to light on when i press a push button. I am using AT89S52 to tests Push Button operation.
I have connected yellow wire to positive and Black wire connected to negative end of breadboard for 5V DC.
Blue connected to Port P0.0 and Green connected to P0.0
Push Button with Resistor = 10 K ohms
I am not getting expected result. I think there should be no problem with hardware connection. I have doubt in program. May be my program is wrong
I am connecting push button to the first bit of PORT 0 (P0.0). The LED is connected to the first bit of PORT 2 (P2.0). I am trying to get an LED to light on when i press a push button. I am using AT89S52 to tests Push Button operation.
I have connected yellow wire to positive and Black wire connected to negative end of breadboard for 5V DC.
Blue connected to Port P0.0 and Green connected to P0.0
Push Button with Resistor = 10 K ohms
C:
#include <reg51.h>
sbit PushButton = P0^0; //PushButton connected to P0.0
sbit LED = P2^0; //LED connected to p2.0
#define ON 1
#define OFF 0
#define press 1
void main()
{
PushButton = 1; // make P0.0 an input!!
while(1) // For ever
{
if(PushButton == press) // if press Push button
{
LED = OFF;
while(PushButton == press); // Wait here for release of push button
}
LED = ON;
}
}
Last edited: