MSP430F169看门狗程序

  1. 看门狗用作定时器,DCO
#include <msp430f169.h>

int main(void)
{
    WDTCTL = WDT_MDLY_32;                   // Set Watchdog Timer interval to ~30ms
    IE1 |= WDTIE;                           // Enable WDT interrupt
    P6DIR |= 0x01;                          // Set P6.0 to output direction

    _EINT();
    LPM0;                                   // Enter LPM0 w/ interrupt
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void){
    P6OUT ^= 0x01;                         // Toggle P6.0 using exclusive-OR
}
  1. 看门狗用作定时器,ACLK
#include <msp430f169.h>

int main(void)
{
    WDTCTL = WDT_ADLY_250;                    // WDT 250ms, ACLK, interval timer
    IE1 |= WDTIE;                             // Enable WDT interrupt
    P6DIR |= 0x01;                            // Set P1.0 to output direction

    _EINT()
    LPM3;                                     // Enter LPM3 w/interrupt
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
    P6OUT ^= 0x01;                            // Toggle P1.0 using exclusive-OR
}
  1. 看门狗用作定时器,XT2CLK
#include <msp430f169.h>

int main(void)
{
    volatile unsigned int i;
    WDTCTL = WDT_ADLY_1000;                   // ACLK / 512, interval timer
    BCSCTL1 &= ~XTS;                          // XT2CLK
    BCSCTL1 &= ~XT2OFF;

    do
    {
        IFG1 &= ~OFIFG;                       // Clear OSCFault flag
        for (i = 0xFF; i > 0; i--)
            ;                                 // Time for flag to set
    }
    while ((IFG1 & OFIFG));                   // OSCFault flag still set?

    BCSCTL2 |= SELM_2;                        // MCLK = LFXT1 (safe)
    BCSCTL2 |= DIVM_3;

    IE1 |= WDTIE;                             // Enable WDT interrupt
    P6DIR |= 0x81;                            // Set P1.0 to output direction

    _EINT();
    LPM0;                                     // Enter LPM0 w/ interrupt
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
    P6OUT ^= 0x81;                            // Toggle P1.0 using exclusive-OR
}

人就像是被蒙着眼推磨的驴子,生活就像一条鞭子;当鞭子抽到你背上时,你就只能一直往前走,虽然连你也不知道要走到什么时候为止,便一直这么坚持着。