4.WDT程序:
默认在中断中SR清零,也就是GIE是0,所以默认不会发生中断嵌套。只有在中断服务程序中打开GIE才能发生中断嵌套。 #include <msp430x14x.h>
unsigned int i=0;
void main(void)
{
WDTCTL = WDT_MDLY_32; // Set Watchdog Timer interval to ~30ms
IE1 |= WDTIE; // Enable WDT interrupt
P2DIR =0xFF; // Set P1.0 to output direction
P2OUT = 0xFF;
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
P2OUT = ~(0x80>>(i++)); // Toggle P1.0 using exclusive-OR
if(8==i) i=0;
}
|