This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IO中断 服务子程序



我想写一个P2.3口的中断,不知道中断服务子程序怎么写,还请赐教。给个例子最好

  • int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      P1DIR = 0x01;                             // P1.0 output, else input
      P1OUT =  0x10;                            // P1.4 set, else reset
      P1REN |= 0x10;                            // P1.4 pullup
      P1IE |= 0x10;                             // P1.4 interrupt enabled
      P1IES |= 0x10;                            // P1.4 Hi/lo edge
      P1IFG &= ~0x10;                           // P1.4 IFG cleared

      _BIS_SR(LPM4_bits + GIE);                 // Enter LPM4 w/interrupt
    }

    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
      P1OUT ^= 0x01;                            // P1.0 = toggle
      P1IFG &= ~0x10;                           // P1.4 IFG cleared
    }

    例子是用P1.4作为中断口,供您参考。