I have a PIC starter kit. I am doing a simple program of turning on led when switch is pressed and then turning them off when switch is released like following:
if(switch==1)
{
led = 1;
}
else
{
led = 0;
}
I was actually not able to do above code in MPLAB. Then I found a tutorial online. I used that code and it was working.
Switch is connected to RD7
Led is connected to RD0
CODE
if(PORTAbits.RD7 == 0)
{
PORTDbits.RD0 = 1;
}
else if(PORTAbits.RD7 == 1)
{
PORTDbits.RD0 = 0;
}
Now I am confused. Why led is turning on when switch(RD7)
is low. Can anyone explain me this logic.?