|
GPIO Interrupt controller
[复制链接]
主晶片:MSP430G2553
目的:透過簡單的GPIO中斷,控制LED以及馬達輸出。
程式碼如下。
- #include <msp430g2553.h>
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Disable watchdog
- P1DIR |= BIT0+BIT4; //Setting P1.0 output
- P1OUT |= BIT0+BIT4; //Setting P1.0 high
- P1REN |= BIT3; //Enable internal pull up/down resistor.
- P1IES |= BIT3; //High to Low edge active
- P1IE |= BIT3; //Enable P1.3 interrupt
- P1IFG &= 0x00; //Clear interrupt flag
- _EINT(); //Enable main switch of the interrupt
- }
- #pragma vector = PORT1_VECTOR //Interrupt Vector
- __interrupt void Port_1(void)
- {
- if(P1IFG&BIT3) //Check interrupt flag
- {
- __delay_cycles(250000); //debounce
- P1OUT ^= BIT0+BIT4; //LED1 inverter
- P1IFG &= 0x00; //Clear flag
- P1REN |= BIT3;
- }
- }
复制代码
|
|