MSP430F5529 IO port pin interrupt study notes
[Copy link]
A very simple program, using the IO interrupt of the key to control the LED on and off on the F5529 development board:
#include
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; //Set the IO port P1.0 corresponding to LED1 to output
P1OUT &= ~BIT0; //Initialize the light to off
P1DIR &= ~BIT7; //Set the IO port P1.7 corresponding to button 1 as input
P1IFG &= ~BIT7; //Initialize and clear the interrupt flag
P1IE |= BIT7; //P1.7 interrupt enable
P1IES |= BIT7; //Falling edge generates interrupt
P1OUT |= BIT7; //P1.7 is set as a pull-up resistor: OUT = 1; REN = 1;
P1REN |= BIT7;
__enable_interrupt();
while(1);
}
#pragma vector = PORT1_VECTOR //Fixed format, declare interrupt vector address, cannot be changed
__interrupt void LED(void) //Function name, can be defined arbitrarily
{
int i;
switch(__even_in_range(P1IV,18))
{
case 0x10:
for (i = 0; i < 12000; i++);
if ((P1IN & BIT7) == 0) //Pay attention to the priority of bit operations!!! Very important
P1OUT ^= BIT0;
break;
default:
break;
}
}
Experience summary:
1. Keys need to be delayed to eliminate jitter
2. The flag bit needs to be manually cleared (this is not completely correct, there are still issues to consider)
3. Interrupt program format:
#pragma vector = PORT2_VECTOR //Fixed format, declare interrupt vector address, cannot be changed
__interrupt void fuck430(void) //Function name, can be defined arbitrarily
{
switch(__even_in_range(P2IV,18))
{
case 0x06:
…
break;
default:
break;
}
}
4. In the main program, you need to open the general interrupt, and then have a loop
5. Bit operations have a very low priority, so be careful to add brackets
6. Pull-up resistors for buttons, OUT, REN, IES
I finally understood IO interrupts in the morning and learned the lesson of bit operation priority.
|