Hi,
I'm attempting to use the push buttons on the exp-msp430f5438A board to put the LCD in standby. I think I've added all the necessary code but, when I press the button it doesn't work.
Using SPPLEDemo I've added the following code. In the beginning of Main.c around line 20. Not inside any function.
volatile unsigned char buttonsPressed;
volatile unsigned char buttonDebounce;
void startWDT()
{
//WDT as 250ms interval counter
SFRIFG1 &= ~WDTIFG;
WDTCTL = WDTPW + WDTSSEL_1 + WDTTMSEL + WDTCNTCL + WDTIS_5;
SFRIE1 |= WDTIE;
}
#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR(void)
{
if (buttonDebounce == 2)
{
buttonDebounce = 1;
SFRIFG1 &= ~WDTIFG;
SFRIE1 &= ~WDTIE;
WDTCTL = WDTPW + WDTHOLD;
}
}
#pragma vector=PORT2_VECTOR
__interrupt void Port2_ISR(void)
{
if (buttonDebounce == 1)
{
buttonsPressed = P2IFG;
buttonDebounce = 2;
startWDT();
__bic_SR_register_on_exit(LPM3_bits);
}
else if (0 == buttonDebounce)
{
buttonsPressed = P2IFG;
__bic_SR_register_on_exit(LPM4_bits);
}
P2IFG = 0;
}
I've added the following code under the function Main ()
//Initialize buttons
buttonDebounce = 1;
halButtonsInit(BUTTON_ALL);
halButtonsInterruptEnable(BUTTON_ALL);
And lastly I've added the following code under the function MainThread()
if (!halButtonsPressed())
{
halLcdStandby();
halLcdSetBackLight(0);
}
I get no errors but, it doesn't work when I press s1 or s2 buttons. Is there a simpler way to just initialize a button and use it in the code to trigger a function?
Best regards,
Forrest Kimbriel