在CCS中,使用了TA0,TA1,TA2,TB0 都 是做为计数用。但是在写中断部分的时候不知道怎么处理。 其中TA0中断是可以正常进入,TA1无法进入,TA2和TB0无法编译。
贴代码请各位看下中断部分应该怎么写。
// 初使化
void Timer_init(void)
{
//计数器 TA0 初使化
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN0); //TA0CLK: GM pulse
// TA0CCTL0 &= ~CCIE; //CCR0 interrupt disable
TA0CCR0 = COUNT_INT_VALUE; // CCR0
TA0CTL = TASSEL_0 + MC_1 + TACLR; //TACLK, up mode, clear TAR counter
TA0CCTL0 |= CCIE; //CCR0 interrupt enable
//计数器 TA1 初使化
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6); //TA0CLK: GM pulse
TA1CCR0 = COUNT_INT_VALUE; // CCR0
TA1CTL = TASSEL_0 + MC_1 + TACLR; //TACLK, up mode, clear TAR counter
TA1CCTL0 |= CCIE; //CCR0 interrupt enable
// TA0CCTL0 &= ~CCIE; //CCR0 interrupt disable
//计数器 TA2 初使化
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2, GPIO_PIN2); //TA0CLK: GM pulse
TA2CCR0 = COUNT_INT_VALUE; // CCR0
TA2CTL = TASSEL_0 + MC_1 + TACLR; //TACLK, up mode, clear TAR counter
TA2CCTL0 |= CCIE; //CCR0 interrupt enable
// TA0CCTL0 &= ~CCIE; //CCR0 interrupt disable
//计数器 TA0 初使化
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P7, GPIO_PIN7); //TA0CLK: GM pulse
TB0CCR0 = COUNT_INT_VALUE; // CCR0
TB0CTL = TBSSEL_0 + MC_1 + TBCLR; //TACLK, up mode, clear TAR counter
TB0CCTL0 |= CCIE; //CCR0 interrupt enable
// TA0CCTL0 &= ~CCIE; //CCR0 interrupt disable
}
void Get_counter(void)
{
TA0CTL=MC_0;
TA1CTL=MC_0;
TA2CTL=MC_0;
TB0CTL=MC_0;
counter_ch1 = counter_ch1+TA0R;
counter_ch2 = counter_ch2+TA1R;
counter_ch3 = counter_ch3+TA2R;
counter_ch4 = counter_ch4+TB0R;
/*
TA0CTL = TASSEL_0 + MC_1 + TACLR; //TACLK, up mode, clear TAR counter ta0
TA1CTL = TASSEL_0 + MC_1 + TACLR; //TACLK, up mode, clear TAR counter ta1
TA2CTL = TASSEL_0 + MC_1 + TACLR; //TACLK, up mode, clear TAR counter ta0
TB0CTL = TBSSEL_0 + MC_1 + TBCLR; //TACLK, up mode, clear TAR counter ta1
*/
TA0CTL = TASSEL_0 + MC_1; //TACLK, up mode, clear TAR counter ta0
TA1CTL = TASSEL_0 + MC_1 ; //TACLK, up mode, clear TAR counter ta1
TA2CTL = TASSEL_0 + MC_1 ; //TACLK, up mode, clear TAR counter ta0
TB0CTL = TBSSEL_0 + MC_1 ; //TACLK, up mode, clear TAR counter ta1
}
以下为中断部分,其中TIMER0_A0_VECTOR 是正确的。
//******************************************************************************
//
// TA0 Interrupt function for gm pulse overflow
//
//******************************************************************************
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR (void)
{
counter_ch1 = counter_ch1+COUNT_INT_VALUE;
}
//******************************************************************************
//
// TA1 Interrupt function for gm pulse overflow
//
//******************************************************************************
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR (void)
{
counter_ch2 = counter_ch2+COUNT_INT_VALUE;
}
//******************************************************************************
//
// TA1 Interrupt function for gm pulse overflow
//
//******************************************************************************
#pragma vector=TIMER0_A2_VECTOR
__interrupt void TIMERA_A2_ISR (void)
{
counter_ch3 = counter_ch3+COUNT_INT_VALUE;
}
//******************************************************************************
//
// TA1 Interrupt function for gm pulse overflow
//
//******************************************************************************
#pragma vector=TIMERB_B0_VECTOR
__interrupt void TIMERB_B0_ISR (void)
{
counter_ch4 = counter_ch4+COUNT_INT_VALUE;
}
补充一下。 在主程序里,每秒中读计数器里的数值是有的。就是中断不对。
void main(void)
{
WDT_A_hold(WDT_A_BASE);
PORT_init();
UCS_init();
RTC_init();
Timer_init();
__bis_SR_register(GIE);
__no_operation();
while(1)
{
key= P2IN & KEY_PIN;
_NOP();
GPIO_toggleOutputOnPin(GPIO_PORT_P3, GPIO_PIN7);
if(sec==1)
{
//Toggle P1.0 every second
// GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
Get_counter();
newTime = RTC_A_getCalendarTime(RTC_A_BASE);
GPIO_toggleOutputOnPin(GPIO_PORT_P4, GPIO_PIN7);
sec=0;
}
}
}