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.

新手学MSP430F5529看门狗



这是一个关于看门狗定时器的程序,但是为什么灯就是闪不起来呢?

/*首先将WDT设为定时器功能。而中断服务子程序则是把WDT改为看门狗功能*/
#include<msp430.h>
void main(void)
{
/*清零-设定为定时器-时间设定为011模式即16S*/
WDTCTL=WDTPW+WDTCNTCL+WDTTMSEL+WDTIS1+WDTIS0;
P1DIR=0xff;
int i,j;
for(i=0;i<15000;i++);
P1OUT=0x00;
for(i=0;i<15000;i++);
P1OUT=0xff;
while(1);
}

#pragma vector=WDT_VECTOR
__interrupt void WatchTimer(void)
{
WDTCTL=WDTPW+WDTCNTCL+WDTIS2; //看门狗模式,时间设定为1S
}

  • 请参考官方例程。

  • 是原理有问题,还是某些细节有问题啊。能不能说一下,非常感谢

  • ZhaoF,

    你程序中都没有把WDT用作定时器时对应的中断打开,也没有把全局中断GIE打开,怎么可能进入中断,怎么可能改为看门狗让其自动复位。请参考TI例程和user guide进行程序编写。

    下程序是code example中的第一个有福安WDT的例程。

    //******************************************************************************
    // MSP430F552x Demo - WDT, Toggle P1.0, Interval Overflow ISR, DCO SMCLK
    //
    // Description: Toggle P1.0 using software timed by the WDT ISR. Toggle rate
    // is approximately 30ms = {(default DCO 1.045MHz) / 32768} based on default
    // DCO = SMCLK clock source used in this example for the WDT.
    // ACLK = n/a, MCLK = SMCLK = default DCO ~1.045MHz
    //
    // MSP430F552x
    // -----------------
    // /|\| |
    // | | |
    // --|RST |
    // | |
    // | P1.0|-->LED
    //
    // Bhargavi Nisarga
    // Texas Instruments Inc.
    // April 2009
    // Built with CCSv4 and IAR Embedded Workbench Version: 4.21
    //******************************************************************************

    #include <msp430.h>

    int main(void)
    {
    WDTCTL = WDT_MDLY_32; // WDT 32ms, SMCLK, interval timer
    SFRIE1 |= WDTIE; // Enable WDT interrupt
    P1DIR |= 0x01; // Set P1.0 to output direction

    __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
    __no_operation(); // For debugger
    }

    // Watchdog Timer interrupt service routine
    #pragma vector=WDT_VECTOR
    __interrupt void WDT_ISR(void)
    {
    P1OUT ^= 0x01; // Toggle P1.0 (LED)
    }


  • 非常感谢。刚开始学,一不小心就把中断使能忘记了