机械按键都有抖动,所以,为了消除按键的抖动,避免各种干扰引起的抖动产生误操作,所以,消抖就变得尤为重要。
#include "MSP430G2553.h"
int ms,k,i;
char key=0;
void delay(int ms)
{
while(ms--)
{
for(i=0;i<120;i++);
}
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR |=BIT6+BIT0;
P1DIR &=~BIT3;
P1IE |=BIT3;
P1IES |=BIT3;
P1IFG &=~BIT3;
_EINT();
while(1)
{
for(k=0;k<22;k++)
{
P1OUT=jj[k];
delay(100);
}
}
}
#pragma vector=PORT1_VECTOR
__interrupt void zhansan(void)
{
key=P1IN & P1IFG;
delay(2);
if(key==(P1IN & BIT3)) //以上三句为消抖
{
for(k=0;k<5;k++)
{
P1OUT |=BIT6+BIT0;
delay(1000);
P1OUT &=~(BIT6+BIT0);
delay(1000);
}
}
P1IFG &=~BIT3;
}