interrupt - MSP430:尝试使用按钮和 LED 闪烁来学习中断
问题描述
我是第一次学习 MSP430,并试图自学中断。
我正在尝试遵循这些示例1 2 3 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
}
}
解决方案
在 MSP430FR6989 LaunchPad 上,P1.3 未连接到按钮。请改用 P1.1。
该按钮需要一个上拉电阻,因此您必须在 P1REN 和 P1OUT 中对其进行配置。
在 P1IES 中为中断配置信号沿可能是个好主意。
您必须清除 LOCKLPM5 才能激活端口设置。
所有这些都可以在msp430fr69xx_p1_03.c
示例程序中看到。
推荐阅读
- javascript - 如何遍历Object然后得到IndexOf字符串,例如A,B..然后如果A = 1,b = 2则转换为值
- c# - RadCombobox SelectedValue 为 Null
- mysql - MySQL 根据列值的优先级进行选择
- android - 最后带有固定字符的可编辑文本
- airflow - Apache Airflow 忽略失败的任务
- ffmpeg - FFmpeg - 缓冲区队列溢出,丢弃 - 组合 2 个视频并使用 concat、hstack 和 trim 时
- microsoft-graph-api - Graph Explorer 似乎不支持 EDU 端点
- python - pandas.read_csv 在导入时更改值
- python - Python:拆分未知长度的输入并创建一个数组
- ms-access - 访问 VBA - 如果记录不存在,则插入到另一个表