锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

NXP_LPC1114延时函数集合

时间:2024-05-26 23:37:11

#include "LPC11XX.h"#include "gpio.h"#include "timer16.h"/*系统时钟配置为48MHz,AHB不分频,一次定时器时钟为48Mhz,因此得出以下分频值,匹配值*/void Delay_Us(unsigned int DelayTimes){ /* * setup timer #1 for delay */  //LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);     /*开启定时器Timer16_1时钟--时钟配置中开启该时钟*/  LPC_TMR16B1->TCR = 0x02;                 /* reset timer */  LPC_TMR16B1->PR  = 48;                   /* set prescaler to zero 根据AHB时钟确定分频值*/  LPC_TMR16B1->MR0 = DelayTimes;             /* 所需的延时时间 */  LPC_TMR16B1->IR  = 0xff;                 /* reset all interrrupts 复位所有的中断*/  LPC_TMR16B1->MCR = 0x04;                 /* stop timer on match --达到匹配停止*/  LPC_TMR16B1->TCR = 0x01;                 /* start timer 启动定时器*/  while (LPC_TMR16B1->TCR & 0x01);           /*等待直到时间到*/ LPC_TMR16B1->TCR = 0x00;                 /* Close timer --关闭定时器*/}void Delay_Ms(unsigned int DelayTimes){ /* * setup timer #1 for delay */  //LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);       //开启定时器Timer16_1时钟  LPC_TMR16B1->TCR = 0x02;                 /* reset timer */  LPC_TMR16B1->PR  = 48000;                 /* set prescaler to zero */  LPC_TMR16B1->MR0 = DelayTimes;  LPC_TMR16B1->IR  = 0xff;                 /* reset all interrrupts */  LPC_TMR16B1->MCR = 0x04;                 /* stop timer on match */  LPC_TMR16B1->TCR = 0x01;                 /* start timer */  while (LPC_TMR16B1->TCR & 0x01);           /*等待直到时间到*/ LPC_TMR16B1->TCR = 0x00;                 /* Close timer */}void Delay_Sec(unsigned char DelayTimes){ /* * setup timer #1 for delay */  //LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);       //开启定时器Timer16_1时钟  LPC_TMR16B1->TCR = 0x02;                 /* reset timer */  LPC_TMR16B1->PR  = 48000000;             /* set prescaler to zero */  LPC_TMR16B1->MR0 = DelayTimes;  LPC_TMR16B1->IR  = 0xff;                 /* reset all interrrupts */  LPC_TMR16B1->MCR = 0x04;                 /* stop timer on match */  LPC_TMR16B1->TCR = 0x01;                 /* start timer */  while (LPC_TMR16B1->TCR & 0x01);           /*等待直到时间到*/ LPC_TMR16B1->TCR = 0x00;                 /* Close timer */}

-电子元器件采购网(www.ruidan.com)是本土元器件目录分销商,采用“小批量、现货、样品”销售模式,致力于满足客户多型号、高质量、快速交付的采购需求。 自建高效智能仓储,拥有自营库存超过50,000种,提供一站式正品现货采购、个性化解决方案、选型替代等多元化服务。
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章