1509 views|0 replies

2015

Posts

0

Resources
The OP
 

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.

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list