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.

定时器B的中断问题

Other Parts Discussed in Thread: MSP430F449

#include <msp430x44x.h>
int y;
void main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  TACTL=TASSEL1+TACLR+TAIE;//TBCTL=TBSSEL1+TBCLR+TBIE;
  TACCR0=100;//TBCCR0=100;
  TACTL|=MC0;//TBCTL|=MC0;
  _EINT();
  while(1);
  
}
#pragma vector=TIMERA1_VECTOR//#pragma vector=TIMERB1_VECTOR
__interrupt void w(void)
{
  y=TAIV;//  y=TBIV;
}
这段程序在IAR Embedded Workbench环境中软件仿真是可以进入中断的,但是仿此,将定时器A改为定时器B,即将上述程序中具有双斜杠的的语句,用双斜杠后面的语句代替前面的指令。仿真根本不进入中断。这是什么原因呢?

  • //******************************************************************************
    // MSP-FET430P440 Demo - Timer_B, Toggle P5.1, Overflow ISR, DCO SMCLK
    //
    // Description: This program toggles P5.1 using software and the Timer_B
    // overflow ISR. In this example an ISR triggers when TB overflows.
    // Inside the ISR P5.1 is toggled. Toggle rate is 16Hz when using
    // default FLL+ register settings and an external 32kHz watch crystal.
    // Proper use of the TBIV interrupt vector generator is demonstrated.
    // ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
    // //* An external watch crystal between XIN & XOUT is required for ACLK *//
    //
    // MSP430F449
    // ---------------
    // /|\| XIN|-
    // | | | 32kHz
    // --|RST XOUT|-
    // | |
    // | P5.1|-->LED
    //
    // M. Buccini
    // Texas Instruments Inc.
    // Feb 2005
    // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
    //******************************************************************************
    #include <msp430.h>

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    FLL_CTL0 |= XCAP14PF; // Configure load caps
    P5DIR |= 0x02; // Set P5.1 to output direction
    TBCTL = TBSSEL1 + TBCLR + TBIE; // SMCLK, clr. TBR, interrupt
    TBCTL |= MC1; // Start Timer_B in continuous mode
    TBCTL = TBSSEL_2 + MC_2 + TBIE; // SMCLK, contmode, interrupt

    _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
    }

    // Timer_B7 Interrupt Vector (TBIV) handler
    #pragma vector=TIMERB1_VECTOR
    __interrupt void Timer_B(void)
    {
    switch( TBIV )
    {
    case 2: break; // CCR1 not used
    case 4: break; // CCR2 not used
    case 14: P5OUT ^= 0x02; // overflow
    break;
    }
    }

  • 再仔细看你的程序和数据手册吧,虽然定时器一样使用,但是并不是你想像的A换成B即可,好好看看。定时器我用的好几个都没问题。我用4xx做了好几个项目了。

  • 你好:

    看起来应该没什么问题,你进入仿真,然后看看TimerB的计数情况正常否。

    谢谢。