第一
//output mode
#include "io430.h"
#include "intrinsics.h"
int main(void)
{
WDTCTL=WDTPW+WDTHOLD;//禁止看门狗记数
 1DIR=0X41;//配置两个LED引脚为输出状态
 1OUT=0X01;//初始化LED状态
while(1)
{
__delay_cycles(500000);
P1OUT^=0X41;
}
}
第二
//intput mode
#include "io430.h"
#include "intrinsics.h"
int main(void)
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR=0X41;
P1OUT=0X09;
P1REN=0X08;
while(1)
{
if(!(P1IN&0X08))
{
__delay_cycles(5000);
if(!(P1IN&0X08))
{
while(!(P1IN&0X08));
P1OUT^=0X41;
}
}
}
}
第三
//INTERRRUPT mode
#include "io430.h"
#include "intrinsics.h"
int main(void)
{
WDTCTL= WDTPW+WDTHOLD;
 1DIR=0X41;
 1OUT=0X09;
 1REN=0X08;//设置上拉电阻
 1IE|=0X08;
 1IES=0X00;
 1IFG=0X00;
__enable_interrupt();
while(1)
{
;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT^=0X41;
P1IFG&=~0X08;
}
|