i've written a small program for the MSP430FR6989 to toggle the LED as long as the Button is pressed.
#include <msp430.h>
/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
PM5CTL0 &= ~LOCKLPM5;
// reset port 1
P1DIR = 0x00;
P1OUT = 0x00;
// turn off led on startup
P1DIR |= BIT0;
P1OUT &= ~BIT0;
P1DIR &= ~BIT1; // P1.1 -> input
P1REN |= BIT1; // P1.1 -> enable resistor
P1OUT |= BIT1; // P1.1 -> pull-up resistor
// enable on P1.1
P1IES |= BIT1;
P1IE |= BIT1;
P1IFG = 0x00;
__enable_interrupt();
while(1)
{
__delay_cycles(1000);
}
return 0;
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
switch (__even_in_range(P1IV, P1IV_P1IFG1))
{
case P1IV_P1IFG1:
P1OUT = (P1IN & BIT1)
? P1OUT & ~BIT0
: P1OUT | BIT0;
P1IES ^= BIT1;
break;
default:
break;
}
}
Everything works as expected. BUT: When I debug the program I see that BIT0 in P1IFG is set as soon as I pressed the button for the first time. Why is this happening? I thought it would only be set if I enable the corresponding IE-Bit?
Thanks in advance