154
Simulation
Explanation
WDT+ is used here as an interval timer with a time period of 512 microseconds. After every 512
microseconds, there is a WDT+ interrupt.
/*
* WDTCTL, Watchdog Timer+ Register
*
* WDTPW -- Watchdog password
* ~WDTHOLD -- Watchdog timer+ is not stopped
* ~WDTNMIES -- NMI on rising edge
* ~WDTNMI -- Reset function
* WDTTMSEL -- Interval timer mode
* ~WDTCNTCL -- No action
* ~WDTSSEL -- SMCLK
* ~WDTIS0 -- Watchdog clock source bit0 disabled
* WDTIS1 -- Watchdog clock source bit1 enabled
*
* Note: ~<BIT> indicates that <BIT> has value zero
*/
WDTCTL = WDTPW | WDTTMSEL | WDTIS1;
Inside this interrupt we just change the value of a variable called task.
#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR_HOOK(void)
{
task++;
if(task >= 3)
{
task = 0;
}
IFG1 &= ~WDTIFG;
}