msp430g2553按鍵控制LED亮滅

實現每按一次button,LED輸出翻轉一次。
仿真如下:
每按一次P1.3的button,p1.6連的LED翻轉一次;

代碼說明:
每按一次button,觸發一次引腳中斷,執行一次 P1_3ISR() 中斷函數

#include <msp430.h>

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR = BIT6; //p1.0,p1.6外接LED爲輸出狀態
P1OUT &= ~ BIT6;
P1REN |= BIT3; //pull up
P1OUT |= BIT3;
P1IE |= BIT3; //P1.3中斷使能
P1IES |= BIT3; //P1.3下降沿有效
P1IFG &= ~BIT3; //P1.3中斷標誌位清零
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}


// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=PORT1_VECTOR
__interrupt void P1_3ISR(void)
{
P1IFG &= ~BIT3;//中斷標誌位清零
P1OUT ^= BIT6;//P1.6狀態翻轉
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章