我是第一次学习MSP430,并试图自学中断。
我正在尝试遵循这些示例 1 2 3 4。 我正在使用MSP430FR6989评估板并在代码编辑器工作室中编写代码。
我试图在按下 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
}
}
在MSP430FR6989启动板上,P1.3 未连接到按钮。请改用 P1.1。
该按钮需要一个上拉电阻,因此您必须在P1REN和P1OUT中对其进行配置。
在P1IES 中为中断配置信号边沿可能是个好主意。
您必须清除LOCKLPM5才能激活端口设置。
所有这些都可以在msp430fr69xx_p1_03.c
示例程序中看到。