您的位置 首页 厂商

LPC1114_时钟体系解析

一般我们在main()的开始部分都需要进行时钟的初始化,根据需要可以选择时钟源、是否开启PLL倍频、以及PLL配置达到所需要的输出时钟,然后再

一般咱们在main()的开端部分都需求进行时钟的初始化,根据需求能够挑选时钟源、是否敞开PLL倍频、以及PLL装备到达所需求的输出时钟,然后再挑选倍频后的时钟作为主时钟源。

如下图:需求留意几个时钟的概念,

#define CLOCK_SETUP           1#define MAIN_PLL_SETUP        1#define MAIN_CLKSRCSEL_Val    0x00000001#define MAIN_PLL_M_Val        0x00000003#define MAIN_PLL_P_Val        0x00000001#define SYS_AHB_DIV_Val       1   /* 1 through 255, typical is 1 or 2 or 4 */#define XTAL        (12000000UL)        /* Oscillator frequency               */#define OSC_CLK     (      XTAL)        /* Main oscillator frequency          */#define IRC_OSC     (12000000UL)        /* Internal RC oscillator frequency   */#define WDT_OSC     (  250000UL)        /* WDT oscillator frequency           */uint32_t ClockSource = IRC_OSC;uint32_t SystemFrequency = IRC_OSC; /*!< System Clock Frequency (Core Clock)  */uint32_t SystemAHBFrequency = IRC_OSC;void Main_PLL_Setup ( void ){uint32_t regVal;ClockSource = OSC_CLK;LPC_SYSCON->SYSPLLCLKSEL = MAIN_CLKSRCSEL_Val;   /* Select system OSC--体系振荡器 */LPC_SYSCON->SYSPLLCLKUEN = 0x01;                 /* Update clock source */LPC_SYSCON->SYSPLLCLKUEN = 0x00;                 /* toggle Update register once */LPC_SYSCON->SYSPLLCLKUEN = 0x01;while ( !(LPC_SYSCON->SYSPLLCLKUEN & 0x01) );    /* Wait until updated */regVal = LPC_SYSCON->SYSPLLCTRL;regVal &= ~0x1FF;LPC_SYSCON->SYSPLLCTRL = (regVal | (MAIN_PLL_P_Val<<5) | MAIN_PLL_M_Val);/* P=1, M=4 FCLKOUT=12*4=48Mhz *//* Enable main system PLL, main system PLL bit 7 in PDRUNCFG. */LPC_SYSCON->PDRUNCFG &= ~(0x1<<7);              /* PDRUNCFG第七位写0,即体系PLL上电 */while ( !(LPC_SYSCON->SYSPLLSTAT & 0x01) );     /* Wait until its locked 确认PLL确认今后向下履行 */LPC_SYSCON->MAINCLKSEL = 0x03;                /* Select PLL clock output--挑选PLL输出作为主时钟 */LPC_SYSCON->MAINCLKUEN = 0x01;                /* Update MCLK clock source --答应更新主时钟*/LPC_SYSCON->MAINCLKUEN = 0x00;                /* Toggle update register once */LPC_SYSCON->MAINCLKUEN = 0x01;while ( !(LPC_SYSCON->MAINCLKUEN & 0x01) );     /* Wait until updated 确认主时钟确认今后向下履行 */LPC_SYSCON->SYSAHBCLKDIV = SYS_AHB_DIV_Val;     /* SYS AHB clock, typical is 1 or 2 or 4 --SYSAHBCLKDIV的值为1,即不分频 使AHB时钟设置为48Mhz */#if MAIN_PLL_SETUPSystemFrequency = ClockSource * (MAIN_PLL_M_Val+1);#elseSystemFrequency = ClockSource;#endifSystemAHBFrequency = (uint32_t)(SystemFrequency/SYS_AHB_DIV_Val);return;}/*** Initialize the system** @param  none* @return none** @brief  Setup the microcontroller system.*         Initialize the System and update the SystemFrequency variable.*/void SystemInit (void){uint32_t i;#ifdef __DEBUG_RAM   LPC_SYSCON->SYSMEMREMAP = 0x1;  /* remap to internal RAM */#else#ifdef __DEBUG_FLASH   LPC_SYSCON->SYSMEMREMAP = 0x2;  /* remap to internal flash */#endif#endif#if (CLOCK_SETUP)                       /* Clock Setup *//* bit 0 default is crystal bypass,bit1 0=0~20Mhz crystal input, 1=15~50Mhz crystal input. */LPC_SYSCON->SYSOSCCTRL = 0x00;/* main system OSC run is cleared, bit 5 in PDRUNCFG register */LPC_SYSCON->PDRUNCFG &= ~(0x1<<5);    /* PDRUNCFG的第五位写0,即体系体系振荡器上电 *//* Wait 200us for OSC to be stablized, no statusindication, dummy wait. */for ( i = 0; i < 0x100; i++ );#if (MAIN_PLL_SETUP)Main_PLL_Setup(); #endif#endif /* endif CLOCK_SETUP *//* System clock to the IOCON needs to be enabled ormost of the I/O related peripherals wont work. */LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16);                  //使能IO模块的时钟return;}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/255604.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部