#include<msp430x14x.h>
#define uint unsigned int
//#define KEY_Pressed (P3IN&0xF3)
#define uchar unsigned char
void main(void)
{
uint i;
WDTCTL = WDTPW + WDTHOLD; // stop WDT
P2DIR = 0xff; // P2口输出
P3DIR &=~BIT2; //P3口输入
P2OUT = 0x00;
__delay_cycles(100000);
P2OUT = 0xFF;
while(1)
{
if(!(P3IN&BIT2)) //检测按键状态,如果有键被按下
{
for(i=0;i<4000;i++); //延时消抖
if (!(P3IN&BIT2)) //再次检验按键状态
for(i=0;i<4000;i++);
P2OUT |=0X00; //P2是输出LED
while(!(P3IN&BIT2)) ; //等待按键放开
}
}
} |