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
  • OK.

    Firstly:

    Look at what you've posted. Look at how you've posted it.

    Did you read the information under http://www.keil.com/forum/tips.asp ?

    It's terrible.

    Then:

    Did you read my previous post? did you actually understand it? Your second code snippet (aka mess) indicates that you didn't do at least one of those things

    Then:

    The code snippet is incomplete and has obvious things missing. Example, wtf is flag0? where do you define it? where do you initialise it?

    Then:

    Why are you initialising the UART within a loop like that?

    In summary:

    It's really not very good. My pre-teen daughter recognised some of the faults in what you had posted!

Reply
  • OK.

    Firstly:

    Look at what you've posted. Look at how you've posted it.

    Did you read the information under http://www.keil.com/forum/tips.asp ?

    It's terrible.

    Then:

    Did you read my previous post? did you actually understand it? Your second code snippet (aka mess) indicates that you didn't do at least one of those things

    Then:

    The code snippet is incomplete and has obvious things missing. Example, wtf is flag0? where do you define it? where do you initialise it?

    Then:

    Why are you initialising the UART within a loop like that?

    In summary:

    It's really not very good. My pre-teen daughter recognised some of the faults in what you had posted!

Children
No data