#include "io430.h"
/*
按键控制lLED灯的亮灭,有两种方法.
方法一:中断功能. 方法二:利用 if(P4IN&BIT2)判断即可.
写代码时,尽量按照步骤来,避免因疏忽而浪费大量时间找bug.
*/
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P4DIR |= BIT5;
P4REN |= BIT2;
P4OUT |= BIT2;
P4IES |= BIT2;
P4IFG &= ~BIT2;
P4IE |= BIT2;
__bis_SR_register(LPM4_bits+GIE);
return 0;
}
#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{
//P4OUT &= ~BIT5; //灭了就不能再亮了.
P4OUT ^= BIT5; //亮灭循环
P4IFG &= ~BIT2;
}
|