利用LPC1788的定时器0实现10ms单位的计数器,即每10ms计数增加1.
初始化定时器0
init_timer(1,599990); //10ms为单位 599990=10(60000000/1000-1),LPC1788工作在120MHZ,经PLL分频后的外设时钟PeripheralClock为60MHZ
函数原型:
- uint32_t init_timer ( uint8_t timer_num, uint32_t TimerInterval )
- {
- timer0_counter = 0;
- LPC_SC->PCONP |= (0x01<<1);
- LPC_TIM0->MR0 = TimerInterval;
- LPC_TIM0->MCR = 3; /* Interrupt and Reset on MR0 */
- NVIC_EnableIRQ(TIMER0_IRQn);
- return (TRUE);
- }
使能定时器
定时中断处理- void TIMER0_IRQHandler (void)
- {
- LPC_TIM0->IR = 0x1<<0; /* clear interrupt flag */
- timer0_counter++;
- return;
- }
|