想用TimerA测频。
可是,高度的时候发现,程序一直在对TAIV进行判断。
而且,进入TAIV的时候,TAR并没有到达溢出值呀。
非常困惑。求大神解答。
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BoardConfig(0x88); //打开数码管,关闭流水灯和电平转换 BCSCTL1 &= ~XT2OFF; // XT2on 打开高频晶体振荡器 do { IFG1 &= ~OFIFG; for(unsigned int i = 0xFF;i > 0;i--); } while((IFG1&OFIFG) != 0); // Change the system clock BCSCTL2 |= SELM_2 + DIVM_0 + SELS + DIVS_0; CCTL1 |= CCIE + CAP + CM_1 + CCIS_1 + SCS; // 上升沿捕获 TACTL |= TASSEL_2 + TACLR + TAIE; // SMCLK, contmode TACTL |= MC_2; P2SEL |= BIT2; //P1SEL |= BIT1; //P3DIR |= BIT4; // P3.4 output //P3OUT &= ~BIT4; //P3.4输出1 P4DIR = 0xff; //设置P4,P5的IO方向为输出 P5DIR = 0xff; P4OUT = 0x00; //设置P4,P5的输出初值 P5OUT = 0xff;
_EINT(); //打开全局中断 while(1) { t = 0; if(t == 6) { t = 0; } //for display for(;pos <6;) { display[pos++] = output % 10; output /= 10; } P4OUT = scandata[display[t++]]; P5OUT = ( 0xff ^ ( BIT5 >>t ) ); } }
// Timer A interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A0 (void) { //P3OUT ^= BIT4; // Toggle P3.4 if (flag == 0) { flag = 1; start = CCR0; } if (flag == 1) { flag = 0; end = CCR0; temp = end - start + 65535 * oft; result += temp; cnt++; oft = 0;; if ( cnt == 8 ) { output = result <<3; cnt = 0; pos = 0; } } } // Timer_A Interrupt Vector (TAIV) handler #pragma vector=TIMERA1_VECTOR __interrupt void Timer_A1 (void) { switch( TAIV ) { case 2: if (flag == 0) { flag = 1; start = CCR1; } if (flag == 1) { flag = 0; end = CCR1; temp = end - start + 65535 * oft; result += temp; cnt++; oft = 0;; if ( cnt == 8 ) { output = result <<3; cnt = 0; pos = 0; } } break; // CCR1 not used case 4: break; // CCR2 not used case 10: oft++; // overflow break; } } // void delay(void) { uint tmp; for(tmp = 120;tmp > 0;tmp--); }
|