本帖最后由 杨光光光, 于 2021-9-8 15:43 编辑
//定时器0周期计时
void TIMER_Init()
{
uint32_t u32Prescale;
u32Prescale = 32;
/* Set timer frequency to 1HZ */
TIMER0->CTL = (TIMER0->CTL & ~(TIMER_CTL_OPMODE_Msk | TIMER_CTL_PSC_Msk)) |(TIMER_PERIODIC_MODE | (u32Prescale-1) | TIMER_CTL_INTEN_Msk); //& ~操作是先按位取反再按位与
TIMER0->CMP = __HIRC / u32Prescale;
/* Enable timer interrupt */
NVIC_EnableIRQ(TMR0_IRQn);
/* Start Timer 0 */
TIMER0->CTL |= TIMER_CTL_CNTEN_Msk;
}
//定时器中断服务函数
void TMR0_IRQHandler(void)
{
/* clear timer interrupt flag */
GPIO_SetMode(PB,BIT14,GPIO_MODE_OUTPUT);
PB14=!PB14;
TIMER0->INTSTS = TIMER_INTSTS_TIF_Msk;
}
想问一下大佬,新唐M0的这个评率怎么搞为1HZ的,我是一脸蒙蔽,
|