Hello all.
I connect 1 additional button to port 1 in MSP430FG4618. The button normally open.
i want each press on button, toggle LED on port 2.2. The problem that the build in buttons (the two red buttons) work good . if i press new button on P1.2 for example it toggle the led but if i come back and press on the build in buttons (the two red buttons) they don't work and only button connected to P1.2 continue to toggle if i press it.
I want to accent that i connect the button without resistor but i don't think that is the problem because new button works good separately.
i will be greatful If anyone can help .
#include <msp430xG46x.h> // Library
#include <LCD_defs.h> // Library
#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void)
{
volatile unsigned int i;
/////////////////////////////////////////////////////////////////////////(S1)
if( P1IFG & 0x01 )
{
P2OUT ^= 0x04; //Toggle Port P2.2
i=1500; //Delay, button debounce
do (i--);
while (i !=0);
while (! (P1IN & 0x01)); //Wait for the release of the button
i=1500; //Delay, button debounce
do (i--);
while (i !=0);
P1IFG &= 0x00; //Clean P1.0 Interrupt Flag
}
/////////////////////////////////////////////////////////////////////////(S2)
if( P1IFG & 0x02 )
{
P2OUT ^= 0x04; //Toggle Port P2.2
i=1500; //Delay, button debounce
do (i--);
while (i !=0);
while (! (P1IN & 0x02)); //Wait for the release of the button
i=1500; //Delay, button debounce
do (i--);
while (i !=0);
P1IFG &= 0x00; //Clean P1.1 Interrupt Flag
}
//////////////////////////////////////////////////////////////////////////(3)
if( P1IFG & 0x04 )
{
P2OUT ^= 0x04; //Toggle Port P2.2
i=1500; //Delay, button debounce
do (i--);
while (i !=0);
while (! (P1IN & 0x04)); //Wait for the release of the button
i=1500; //Delay, button debounce
do (i--);
while (i !=0);
P1IFG &= 0x00; //Clean P1.2 Interrupt Flag
}
}
void main (void)
{
WDTCTL = WDTPW | WDTHOLD; //Stop Watchdog Timer
P1SEL &= 0x00;
P2DIR |= 0x04; //Configure P2.2 as Output (LED1)
P1DIR &= ~0xFF; //Configure P1 as Input (S1)
P1IE |= 0xFF; //Interrupt Enable in P1
P1IES |= 0xFF; //P1 Interrupt flag high-to-low transition
_BIS_SR (LPM3_bits + GIE); //Low Power Mode with interrupts enabled
}