首页 > 其他分享 >S32K148-LPTMR(裸机开发)

S32K148-LPTMR(裸机开发)

时间:2022-10-08 08:55:22浏览次数:48  
标签:LPTMR void ptr 裸机 LPTMR0 PCC CSR uint32 S32K148

根据芯片手册进行配置:

//==========================================================================
//初始化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

相关文章

  • S32K148-lptmr配置
    S32K148自带的定时器,配置非常简单,有时候我会用它做任务周期,配置一个1ms定时器中断一次  初始化函数:voidLPTMR_init(void){LPTMR_DRV_Init(INST_LPTMR1,&lpT......
  • S32K148-uart(裸机开发)
    上周分享了基于S32-SDK方法配置uart的方法,本次分享UART底层裸机配置,废话不多数,直接上代码:1)初始化voiduart1_init(void){/**PTC6uart1_rx*PTC7ua......
  • ARM裸机笔记
    汇编指令MRS:MovetoRegisterfromStatusMSR:MovetoStatus from Register指令同MOV,参数前者是目的地,后者是源用于操作PSR(ProgramStatusRegister)  ARM......