我是第一次学习MSP430,并试图自学中断。我正在尝试遵循以下示例123 4。我正在使用MSP430FR6989评估板,并在Code Composer Studio中编写代码。
我试图按下P1.1按钮时(即使用中断)使板上的REDLED切换。我能够使用单独的代码来使LED闪烁,所以我知道开发板可以工作。这是我要开始工作的代码。
#include <msp430.h>
#include "driverlib.h"
int main(void) //Main program
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set P1.0 to output and P1.3 to input direction
P1OUT &= ~BIT0; // set P1.0 to Off
P1IE |= BIT3; // P1.3 interrupt enabled
P1IFG &= ~BIT3; // P1.3 interrupt flag cleared
__bis_SR_register(GIE); // Enable all interrupts
while(1) //Loop forever, we'll do our job in the interrupt routine...
{}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= BIT0; // Toggle P1.0
P1IFG &= ~BIT3; // P1.3 interrupt flag cleared
}
当我按下按钮时,LED指示灯不亮,我不确定为什么。我将不胜感激!
根据用户@CL的要求显示有效的LED闪烁程序
#include <msp430.h>
#include "driverlib.h"
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Disables the watchdog
PM5CTL0 &= ~LOCKLPM5; // allows output pins to be set... turning off pullups
P1DIR = BIT0; // Make a pin an output... RED LED
long x = 0; // Will be used to slow down blinking
while(1) // Continuously repeat everything below
{
for(x=0 ; x < 30000 ; x=x+1); // Count from 0 to 30,000 for a delay
P1OUT = BIT0; // Turn red LED light on
for(x=0 ; x < 30000 ; x=x+1); // Count from 0 to 30,000 for a delay
P1OUT ^= BIT0; // Turn off the red LED light
}
}
在P1IES中为中断配置信号沿可能是个好主意。
您必须清除LOCKLPM5才能激活端口设置。
所有这些都可以在msp430fr69xx_p1_03.c
example program中看到。