打印

LPC11xx自带的Timer16.c文件里面的delayMs函数到底怎么用??

[复制链接]
1606|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
544852010|  楼主 | 2012-11-13 15:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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毫秒,也就是一秒,调试却发现始终没有这一秒的延时,不知道这函数到底怎么使用合适??哪位大侠帮忙指导下啊,谢谢!

相关帖子

沙发
544852010|  楼主 | 2012-11-16 16:12 | 只看该作者
搞定了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:LED行业应用技术支持工程师,欢迎多多交流!QQ-544852

35

主题

68

帖子

1

粉丝