This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2333: Push Button LED

Part Number: MSP430G2333

Hi all,

I am trying to run a simple push button code on MSP430G2333 to toggle. I have been using the following code, however, it does not get through the if statement. The problem is with the push button as the LED works fine without the if condition. I would be thankful if someone can help me out here to get it working.

I am using the pin P2.7 as the input where the button is connected.

I have also read the datasheet and it says that the P2.7 can be used as an input.  If XOUT/P2.7 is used as an input, excess current flows until P2SEL.7 is cleared. This is due to the oscillator output driver connection to this pad after reset.

I am doubting if it has to do with the oscillator output driver connection which is causing the issue, I may be completely off.

#include <msp430.h>
#include <msp430g2333.h>
#define DELAY 150000

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P2DIR = 0x00;
//P2DIR&=~BIT7; //Set P2.7 as input (0 is counted as input )
//P2REN|=BIT7; //Enable pullup/pulldown resistors for P2.7 (enable internal pull up, 1)
//P2OUT&=~BIT7; //Set P2.7 to have pull down resistors ( select pull-down mode, 0)
//P2OUT|=BIT7; //Set P2.7 to have pull up resistors

P1DIR|=BIT0; //Set P1.0 as output
P1OUT|=BIT0; //Initially turn off the RED LED (LED-1R)
// P1OUT&=~BIT0; //Initially turn ON the LED

                        if((P2IN&BIT7)==BIT7) //If the switch is pressed
                                    P1OUT^=BIT0; //Toggle the LED
                                    __delay_cycles(DELAY); //Wait for switch to be unpressed

return 0;

**Attention** This is a public forum