//打开c口5号引脚的相应功能
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; //Turn on PORTA clock
PORTC_PCR5=PORT_PCR_MUX(0x4); //Use ALT2 on PTC 5
// /* Ensure Internal Reference Clock is Enabled * /
MCG_C1|=MCG_C1_IRCLKEN_MASK;
//Enable fast internal ref clock by setting MCG_C2[IRCS]=1
//If wanted to use 32Khz slow mode, set MCG_C2[IRCS]=0 instead
MCG_C2|=MCG_C2_IRCS_MASK;
//Set up GPIO
if(pin_select==LPTMR_ALT1)
{
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; //Turn on PORTA clock
PORTA_PCR19=PORT_PCR_MUX(0x6); //Use ALT6 on PTA19
//printf("Testing ALT1 pin on PORTA19\n");
//printf("\tTWR-K70F120M: ALT1 is conected to pin 18 on J15\n");
}
else if(pin_select==LPTMR_ALT2)
{
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; //Turn on PORTC clock
PORTC_PCR5=PORT_PCR_MUX(0x4); //Use ALT2 on PTC5
}
LPTMR0_PSR=LPTMR_PSR_PCS(0x1)|LPTMR_PSR_PBYP_MASK; //Use LPO clock but bypass glitch filter
LPTMR0_CMR=LPTMR_CMR_COMPARE(compare_value); //Set compare value
LPTMR0_CSR=LPTMR_CSR_TPS(pin_select)|LPTMR_CSR_TMS_MASK; //Set LPT to use the pin selected, and put in pulse count mode, on rising edge (default)
//printf("Press any key to start pulse counter\n");
//in_char(); //wait for keyboard press
// On each read of the LPTMR counter register, software must first write to the *
//LPTMR counter register with any value. This will synchronize and register the *
// current value of the LPTMR counter register into a temporary register. The *
//contents of the temporary register are returned on each read of the LPTMR *
// counter register.
//===============================================================================
uint16 get_counter_value()
{
LPTMR0_CNR=0x1;
return LPTMR0_CNR;
}