我正在为msp430做一个程序。MSP430问题,按钮不关闭
单击第一次按钮时增量就会消失。按钮释放后它不会停止。
如何将增量限制为每次点击一次增量?
#include <msp430.h>
int main(void)
{
int i; //delay variable
int dimeRead=0;
int desired=1000;
volatile int total=0;
P1OUT=0; //Supposed to get rid of it hanging at the top
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
while(total<desired)
{
if((P1IN&0x16)!=0x16) // check if switch is pressed or not
{
dimeRead=dimeRead+1;
total=total + 10;
}
//Goal is to flip an out put on to turn on light when desired number is hit.
}
return 0;
}
你确定关于'0x16' ....我想你需要'0x08'或类似的东西。我的意思是0x16是二进制'10110',你可能想测试一个位。用'0x08',你可以只检查位3,例如 – LPs
告诉我们你有哪个MSP430型号,以及你如何将按钮连接到它。 –
信号去弹跳在哪里?它是通过RC滤波器处理的吗?如果没有,你永远不会得到这个代码工作。你可能打算使用十进制掩码16而不是十六进制0x16。不要使用,使用一个常量'#定义掩码(1 << 4)// pin 4'。 – Lundin