This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reverse working of Switch

When I am executing this code, the LED is ON by default whereas it should only be ON when switch is pressed. And when I press the switch, it turns off. Can anyone please explain me, what I am doing wrong with my code.

</ #include <lpc17xx.h>

#define SwitchPinNumber 11

#define LedPinNumber 6

void main()

{

uint32_t switchStatus;

SystemInit();

LPC_PINCON->PINSEL4 = 0x000000; //Configure the Pins for GPIO;

/* Configure the LED pin as output and SwitchPin as input */

LPC_GPIO2->FIODIR = ((1<<LedPinNumber) | (0<<SwitchPinNumber));

while(1)

{

/* Turn On all the leds and wait for one second */

switchStatus = (LPC_GPIO2->FIOPIN>>SwitchPinNumber) & 0x01 ; //Read switch status

if(switchStatus == 1)

{

LPC_GPIO2->FIOPIN = (1<<LedPinNumber);

}

else

{

LPC_GPIO2->FIOPIN = (0<<LedPinNumber);

}

}

} >

Parents Reply Children