LPTMR0_CSR &=~LPTMR_CSR_TEN_MASK;// Turn off LPTMR before LPTMR register configration
dwData |=(LPTMR_CSR_TIE_MASK\
|LPTMR_CSR_TCF_MASK);// We do this to reduce operations of register to save time
LPTMR0_CSR = dwData;//In this case, we just operate register for once.
LPTMR0_PSR |= LPTMR_PSR_PBYP_MASK;// We donot need to divided the clock any more here
LPTMR0_PSR &= (~LPTMR_PSR_PCS_MASK);// Choose MCGIRCLK as the clock source (1MHz)
LPTMR0_CMR =(wTime*1000);//Then turn it as a period in 1ms
LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;// After all, we turn on LPTMR and start counting
return SW_OK;// That is all
}
I write the comments with English, please forgive me for my zhuangbility. Everybody have fun^-^
Summry: The MCGIRCLK is an internal clock with two clock sources : 32KHz and 4MHz, there seem to be fixed, so you can use them without any care of you crystal clock. In this case, it is a good way for you to realise a driver because it is fixed. May we still need to modify something for other situations, but it works for my application. By the way, 32KHz and 4MHz can be chose by the field IRCS of the register MCG_C2, clear this field will choose the slow clock source 32KHz ,or you can get a 4MHz as mentioned fast clock source by setting this field. Do I need to explain what is "clear" and "set"? I will never tell you that "clear" is writing "0" to a field and "set" is writing "1" to this field.