实验五——利用中断使用按键点灯

写中断函数不同于普通函数,不需要声明
直接用关键字“__interrupt”表明即可

#include  


/**
 * main.c
 */
int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	P3DIR |= BIT7;    //输出模式
	P3OUT &= ~ BIT7;  //关闭LED1
	//配置模式
	P1REN |= BIT3;   //pull up resistor
	P1OUT |= BIT3;   //下拉电阻模式
	P1IES &= ~BIT3;  //high to low,按键下降沿触发
	P1IFG &= ~BIT3;  //clear flag,清除中断
	P1IE |= BIT3;    //enable interrupt
	
    _bis_SR_register(LPM4_bits + GIE);   //低功耗模式
    _no_operation();   //无操作
}

//   中断
    #pragma vector = PORT1_VECTOR
    __interrupt void Port_1(void){
    P3OUT ^= BIT7;    //change LED1
    P1IFG &= ~BIT3;   //clear flag
}

#include  


/**
 * main.c
 */
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
    P8DIR |= BIT1;    //
    P8OUT &= ~ BIT1;
    P1REN |= BIT2;   //pull up resistor
    P1OUT |= BIT2;
    P1IES |= BIT2;  // high to low
    P1IFG &= ~BIT2;  //clear flag
    P1IE |= BIT2;    //interrupt

    _bis_SR_register(LPM4_bits + GIE);
    _no_operation();
}

//   interrupt function
    #pragma vector = PORT1_VECTOR
    __interrupt void Port_1(void){
    P8OUT ^= BIT1;    //change LED1
    P1IES ^= BIT2;    //low to high,松手就是上升沿触发
    P1IFG &= ~BIT2;   //clear flag
}

你可能感兴趣的:(微处理器,c语言)