#include "msp430f5529.h"
#include "msp430.h"
void init_TA1(void) //定时器TA1初始化 CCRO
{
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 50000-1; // 设置计数值
TA1CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK(25MHz), upmode, clear TAR
} // ACLK 32768
void init_TA1_double(void) //定时器TA1初始化 CCR1 和 CCR2两路定时
{
TA1CCTL1 = CCIE; // CCR1 interrupt enabled
TA1CCR1 = 50000-1; // 设置计数值
TA1CCTL2 = CCIE; // CCR2 interrupt enabled
TA1CCR2 = 25000; // 设置计数值
TA1CTL |= TASSEL_2 + MC_1 + TACLR + TAIE; // SMCLK(25MHz), upmode, clear TAR enable interrupt
}
// Timer1 A0 interrupt service routine //CCR0有专门的中断标号TIMER1_A0_VECTOR
#pragma vector=TIMER1_A0_VECTOR //CCR1和CCR2的中断标号都为TIMER1_A1_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
static unsigned short i = 0;
if (i++ >= 250) //0.5S
{
P1OUT ^= 0x01; // Toggle P1.0
i = 0;
}
}
// Timer1 A1 interrupt service routine //CCR0有专门的中断标号TIMER1_A0_VECTOR
#pragma vector=TIMER1_A1_VECTOR //CCR1和CCR2的中断标号都为TIMER1_A1_VECTOR
__interrupt void TIMER1_A1_ISR(void)
{
static unsigned short i = 0, j = 0;
switch(__even_in_range(TA1IV,14))
{
case 0: break; // No interrupt
case 2: // CCR1
if (i++ >= 200)
{
P4OUT ^= BIT7;
i = 0;
}
break;
case 4: // CCR2
if (j++ >= 400)
{
P1OUT ^= BIT0;
j = 0;
ClockUpdate();
}
break;
case 6: break; // reserved
case 8: break; // reserved
case 10: break; // reserved
case 12: break; // reserved
case 14: break; // overflow
default: break;
}
}
上面这段程序TA1 CCR0的中断可以进,但是CCR1和CCR2的中断没有进是怎么回事,特意分开初始化了!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>