/*p1.0 p1.6输出信号,p1.3为按键输入*/
#include
char key_pressed(void);
main()
{
WDTCTL=WDTPW+WDTHOLD; //关闭 watchdog
P1DIR &=~BIT3; //P1.0 P1.6配置输出,p1.3输入
P1OUT=0; //关闭LED
while(1)
{
if(key_pressed())
P1OUT ^= 0x01; // 翻转p1.0电平
}
}
char key_pressed(void)
{
unsigned int i;
while(!(P1IN&BIT3));
for(i=0;i<8000;i++);
if(!(P1IN&BIT3))
return 1;
else
return 0;
} |