LPC11xx自带的Timer16.c文件里面的delayMs函数到底怎么用??
delayMs函数如下:
void delayMs(uint8_t timer_num, uint32_t delayInMs)
{
if (timer_num == 0)
{
/*
* setup timer #0 for delay
*/
LPC_TMR16B0->TCR = 0x02; /* reset timer --TCR用于控制计数器/定时器使能还是复位*/
LPC_TMR16B0->PR = 0x00; /* set prescaler to zero 预分频寄存器*/
LPC_TMR16B0->MR0 = delayInMs * (SystemAHBFrequency / 1000); /*写匹配寄存器*/
LPC_TMR16B0->IR = 0xff; /* reset all interrrupts 中断寄存器*/
LPC_TMR16B0->MCR = 0x04; /* stop timer on match 匹配控制寄存器 是中断还是复位还是停止*/
LPC_TMR16B0->TCR = 0x01; /* start timer 使能计数器-定时器*/
/* wait until delay time has elapsed 等待直到时间到 */
while (LPC_TMR16B0->TCR & 0x01); /* reset timer --时间到TCR0被置0,跳出循环*/
}
else if (timer_num == 1)
{
/*
* setup timer #1 for delay
*/
LPC_TMR16B1->TCR = 0x02; /* reset timer */
LPC_TMR16B1->PR = 0x00; /* set prescaler to zero */
LPC_TMR16B1->MR0 = delayInMs * (SystemAHBFrequency / 1000);
LPC_TMR16B1->IR = 0xff; /* reset all interrrupts */
LPC_TMR16B1->MCR = 0x04; /* stop timer on match */
LPC_TMR16B1->TCR = 0x01; /* start timer */
/* wait until delay time has elapsed */
while (LPC_TMR16B1->TCR & 0x01);
}
return;
}
调用的时候
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); //开启定时器Timer16_0时钟
delayMs(1,1000);
按照意思是延时1000毫秒,也就是一秒,调试却发现始终没有这一秒的延时,不知道这函数到底怎么使用合适??哪位大侠帮忙指导下啊,谢谢! |