常驻嘉宾
- 积分
- 4415
- 威望
- 2369
- 贡献
- 358
- 兑换币
- 1614
- 注册时间
- 2013-9-23
- 在线时间
- 844 小时
|
void Counter0_Init(void)
{
/*First configure the pin of the module will be use*/
SIM->SCGC5 |=(uint32_t)(0x1UL<<11); //open the clock of the PTC
PORTC->PCR[5] &=~(uint32_t)(0x7UL<<8);
PORTC->PCR[5] |=(uint32_t)(0x3UL<<8); //PTC5 for ALT3(LPTMR_ALT2)
/*Configure the module*/
SIM->SCGC5 |=(uint32_t)(0x1UL<<0); //open the clock of the LPTMR0
LPTMR0->CSR =0;
LPTMR0->PSR =0;
LPTMR0->CMR =0xFFFFUL;
LPTMR0->PSR |=(uint32_t)(0x1UL<<2); //prescaler and glitch filter bypassed,if you want to use it,reference the book
LPTMR0->CSR &=~(uint32_t)(0x3UL<<4);
LPTMR0->CSR |=(uint32_t)(0x2UL<<4); //Select the LPTMR_ALT2 as the input clk
LPTMR0->CSR |=(uint32_t)(0x1UL<<1); //counter mode selected
LPTMR0->CSR |=(uint32_t)0x1UL; //enable the counter
}
uint32_t Counter0_Read(void)
{
uint32_t temp=0;
LPTMR0->CNR =0x00;
temp=LPTMR0->CNR;
return temp;
}
void Counter0_Clear(void)
{
LPTMR0->CSR =0;
LPTMR0->PSR =0;
LPTMR0->CMR =0xFFFFUL;
LPTMR0->PSR |=(uint32_t)(0x1UL<<2); //prescaler and glitch filter bypassed,if you want to use it,reference the book
LPTMR0->CSR &=~(uint32_t)(0x3UL<<4);
LPTMR0->CSR |=(uint32_t)(0x2UL<<4); //Select the LPTMR_ALT2 as the input clk
LPTMR0->CSR |=(uint32_t)(0x1UL<<1); //counter mode selected
LPTMR0->CSR |=(uint32_t)0x1UL; //enable the counter
} |
|