根据芯片手册进行配置:
//========================================================================== //初始化LPTMR0 //========================================================================== void lptmr0_init(void) { uint32_t *PCC_LPTMR0_ptr; uint32_t *CSR_ptr; uint32_t *PSR_ptr; uint32_t *CMR_ptr; PCC_LPTMR0_ptr = (uint32_t *)(PCC_BASE + 0x100); *PCC_LPTMR0_ptr |= (1<<31) | (1<<30) |(1<<24);//使能LPTMR0时钟 CSR_ptr = (uint32_t *)LPTMR0_BASE; PSR_ptr = (uint32_t *)(LPTMR0_BASE + 0x4); CMR_ptr = (uint32_t *)(LPTMR0_BASE + 0x8); /* *PSR_ptr = 0x00000005;//lptmr_clk:1khz LPO,presacler bypass
*CMR_ptr = 1000; //1s *CSR_ptr = 0x00000041;//中断使能,定时器模式,开启定时器 */ *PSR_ptr = 0x00000010;//lptmr_clk:8Mhz SIRC,prescaler enbale,precaler value = 8(0010b),分频之后8M/8=1M *CMR_ptr = 1000; //1ms *CSR_ptr = 0x00000041;//中断使能,定时器模式,开启定时器 S32_NVIC_EnableIRQ(LPTMR0_IRQn);//使能中断ID }
void LPTMR0_IRQHandler(void) { LPTMR0->CSR |= (1<<7);//清除中断标志 count_1s++; if(count_1s == 1000) { count_1s = 0; gpio_reverse(PTe, 21); } count_1ms++; /*给2ms任务周期调用*/ count_2ms++; /*给5ms任务周期调用*/ count_5ms++; /*给10ms任务周期调用*/ count_10ms++; /*给100ms任务周期调用*/ count_100ms++; /*给250ms任务周期调用*/ count_250ms++; /*给500ms任务周期调用*/ count_500ms++; /*给1000ms任务周期调用*/ count_1000ms++; }
标签:LPTMR,void,ptr,裸机,LPTMR0,PCC,CSR,uint32,S32K148 From: https://www.cnblogs.com/taotaonihao/p/16721940.html