/**************************************** 测速初始化 捕获模式测速 测速1:TB0.0 P5.6 测速2:TB0.4 P7.6 *****************************************/ void Speed_Check_Init() { TB0CCTL0 |= CCIE + CM_1 + CCIS_0 + CAP + SCS;//捕获中断使能,上升沿捕获,捕获源CCI0A,捕获模式,同步捕获 TB0CCTL4 |= CCIE + CM_1 + CCIS_0 + CAP + SCS;//同上 TB0CCTL1 |= CCIE; TB0CCTL0 &= ~(COV + CCIFG);//清掉TB0.0的COV以及CCIFG TB0CCTL4 &= ~(COV + CCIFG);//清掉TB0.4的COV以及CCIFG TB0CTL |= TBSSEL_1 + MC_2 + TBCLR;//32768HZ,continuous mode TBCCR1 = 3276; __bis_SR_register(GIE); P5DIR &= ~BIT6;//TB0.0捕获输入 P7DIR &= ~BIT6;//TB0.4捕获输入 P5SEL |= BIT6;//设置为第二功能 P7SEL |= BIT6;//设置为第二功能 } /*void Get_Speed() { }*/ /*************************** 计数中断,右轮,TB0.4 100MS定时中断测速 *****************************/ #pragma vector=TIMERB1_VECTOR __interrupt void TIMERB1_ISR(void) { /* Any access, read or write, of the TBIV register automatically resets the highest "pending" interrupt flag. */ switch( __even_in_range(TBIV,14) ) { case 0: break; // No interrupt case 2: TBCCR1 += 3276;//大约100ms测一次速度 Speed_Check_Left = Left_Wheel; Speed_Check_Right = Right_Wheel; Left_Wheel &= 0; Right_Wheel &= 0;//计数清零 break; case 4: break; // CCR2 not used case 6: break; // CCR3 not used case 8: Right_Wheel++; // 脉冲计数加1 break; case 10: break; // CCR5 not used case 12: break; // CCR6 not used case 14: break; // OVERFOLW NOT USED default: break; } } /*************************** 计数中断,左轮,TB0.0 *****************************/ #pragma vector=TIMERB0_VECTOR __interrupt void TIMERB0_ISR(void) { //自动清除中断标志 Left_Wheel++; }