1.看门狗产生方波
1 #include <msp430x14x.h> 2 void main() 3 { 4 WDTCTL = WDT_MDLY_32; 5 IE1 |= WDTIE; 6 P1DIR |= BIT1; 7 _EINT(); 8 } 9 #pragma vector=WDT_VECTOR 10 __interrupt void Watchdog(void) 11 { 12 P1OUT ^= BIT1; 13 }
2.增计数模式
1 #include <msp430x14x.h> 2 void main() 3 { 4 WDTCTL = WDTPW + WDTHOLD; 5 P1DIR |= BIT1; 6 CCTL0 = CCIE; 7 CCR0 = 10000; 8 TACTL = TASSEL_2 + MC_1 + ID_3;
_EINT(); 9 } 10 #pragma vector=TIMERA0_VECTOR 11 __interrupt void Timer_A(void) 12 { 13 P1OUT ^= BIT1; 14 }
3.连续模式
1 #include <msp430x14x.h> 2 void main() 3 { 4 WDTCTL = WDTPW + WDTHOLD; 5 P1DIR |= BIT1; 6 TACTL = TASSEL_2 + MC_2 + ID_3 + TACLR + TAIE; 7 _EINT(); 8 } 9 #pragma vector=TIMERA0_VECTOR 10 __interrupt void Timer_A(void) 11 { 12 switch(TAIV) 13 { 14 case 2:break; 15 case 4:break; 16 case 10:P1OUT ^= BIT1;break; 17 } 18 }
4.增计数与连续模式
1 #include <msp430x14x.h> 2 void main() 3 { 4 WDTCTL = WDTPW + WDTHOLD; 5 P6DIR = 0xff; 6 P6OUT = 0XFF; 7 8 TACCTL0= CCIE; 9 TACCR0 = 50000; 10 11 TACTL = TASSEL_2 + MC_2 + ID_3 + TACLR + TAIE; 12 _EINT(); 13 } 14 15 #pragma vector=TIMERA0_VECTOR 16 __interrupt void Timer_A0(void) 17 { 18 P6OUT = ~(P6OUT & BIT0); 19 TACCR0 = TACCR0 + 50000; 20 } 21 22 #pragma vector=TIMERA1_VECTOR 23 __interrupt void Timer_A1(void) 24 { 25 switch(TAIV) 26 { 27 case 2:break; 28 case 4:break; 29 case 10:P6OUT = ~(P6OUT & BIT7);break; 30 } 31 }