I have connected switch and LED to AT89S52. I want to turn ON LED when switch is ON and turn of LED when switch is OFF. I have written code in Keil for interfacing switch but the problem is when switch is ON, LED doesn't turn ON and when switch is OFF, LED doesn't turn OFF. I measured the output voltage of pin P0.1 It show zero volt. I am trying to solve this problem from last 4-5 hours but nothing happening
Please check out these codes, wiring and help me
AT89S52 wiring with switch
Please check out these codes, wiring and help me
Code:
#include <REG51.h>
sbit Switch = P0^1; //switch connected to P0.1
sbit LED = P2^0; //LED connected to p2.0
#define ON 1
#define OFF 0
void main (void)
{
while(1)
{
if(Switch == ON) //If switch is ON
{
LED = ON; // Turn ON LED
}
else
{
LED = OFF; // Turn OFF LED
}
}
}
Last edited: