Timer A UP mode 中断
Timer_A, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
// Description: Toggle P1.0 using software and TA_0 ISR. Timer_A is
// configured for up mode, thus the timer overflows when TAR counts to CCR0.
1 void Timer0_Init(void) 2 { 3 4 CCTL0 = CCIE; // CCR0 interrupt enabled 5 CCR0 = 5000; //frequency SMCLK/5000*2; 6 TACTL = TASSEL_2 + MC_1; // SMCLK, upmode 7 }
中断函数
1 #pragma vector=TIMER0_A0_VECTOR 2 3 __interrupt void TimerA0(void) 4 5 { 6 7 P1OUT ^= RED_LED; 8 9 }
屏蔽中断:
CCTL0 ^= CCIE; //在开启定时器中断与关闭间转换。
因为同时使用的PWM与此定时器冲突所以又使用了定时器A1
1 void Timer1_Init() 2 3 { 4 5 TA1CCTL0 = CCIE; 6 7 TA1CCR0 = 5000; 8 9 TA1CTL |= TASSEL_2+MC_1+TACLR; 10 11 }
中断
1 #pragma vector=TIMER1_A0_VECTOR 2 3 __interrupt void TimerA1(void) 4 5 { 6 7 P1OUT ^= RED_LED; 8 9 }
注意寄存器名字与中断向量的名字