#include
#include "LCD_Display.h" unsigned int TA_OverflowCnt; // TA overflow times are stored in variables unsigned long int Period; // Pulse width measurement results are stored in variables unsigned int RiseCapVal; // Rising edge capture value is stored in variables unsigned char Edge=0; // Current trigger edge #define RISE 0 #define FALL 1 void main( void ) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog FLL_CTL0 |= XCAP18PF; // Configure crystal load capacitance P1DIR &=~(BIT2); // P1.2(TA1) is set as input (optional) P1SEL |= BIT2; // P1.2 is set as the second function (TA1) TACTL = TASSEL_2 + MC_2 + TAIE + TACLR; // TA counts continuously, starts timing, SMCLK, opens interrupt TACCTL1 = CAP + CM_1 + CCIS_1 + SCS + CCIE; //Capture module 1 starts, selects TA1 (P1.2) pin as the capture source, rising edge capture, synchronous mode, turns on capture interrupt BTCTL=0; LCD_Init(); _EINT(); //General interrupt allows LPM0; // Enter low power mode 3 sleep, all programs are executed in the interrupt } #pragma vector=TIMERA1_VECTOR __interrupt void TA_ISR(void) //Timer_A interrupt { switch( TAIV ) { case 2: // Comparison/capture module 1 interrupt if(Edge==RISE) //If it is a rising edge capture interrupt { RiseCapVal=TACCR1; //Save the capture value at the rising edge TACCTL1 = CAP +CM_2 +CCIS_1 +SCS +CCIE; //Change to falling edge trigger Edge=FALL; //Trigger edge status flag } else //If it is a falling edge capture interrupt { Period=TA_OverflowCnt*65536 + TACCR1 - RiseCapVal;//Calculation period TA_OverflowCnt=0; //Clear overflow times TACCTL1 = CAP +CM_2 +CCIS_1 +SCS +CCIE;//Change to rising edge trigger Edge=FALL; //Trigger edge status flag LCD_DisplayLongNumber(Period); //Display} break; case 4: break; case 10: TA_OverflowCnt++; //TA overflows each time, overflow times variable + 1 break; } }