调试LPC1768, NXP的库如同不如Luminary的好用(我们都这么说,也就跟着随声附和了)。对照LPC1768的手册看了看Keil例程的PLL0装备进程,记载如下:
#if (CLOCK_SETUP)
LPC_SC->SCS = SCS_Val;// 启用外部主时钟
if (SCS_Val & (1 << 5)) {
while ((LPC_SC->SCS & (1<<6)) == 0);
}
//PLL倍频出来的时钟送给CPU前的分频,CCLKCFG_Val=3,为4分频
LPC_SC->CCLKCFG = CCLKCFG_Val;
LPC_SC->PCLKSEL0 = PCLKSEL0_Val;
LPC_SC->PCLKSEL1 = PCLKSEL1_Val;
LPC_SC->CLKSRCSEL = CLKSRCSEL_Val;
#if (PLL0_SETUP)
//PLL0CFG_Val = 0x00050063,5为pre-div的值既N,所以除数为N+1=6
// 0x63为乘数M,M+1=100,记住要把16进制换算为10进制
//Fcco = 2*100*12/6 = 400,然后再除以CPU clock的4,即该设置主频为100M
LPC_SC->PLL0CFG = PLL0CFG_Val;
LPC_SC->PLL0CON = 0x01;
//承认序列
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & (1<<26)));
LPC_SC->PLL0CON = 0x03;
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
#endif
#if (PLL1_SETUP)
LPC_SC->PLL1CFG = PLL1CFG_Val;
LPC_SC->PLL1CON = 0x01;
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
while (!(LPC_SC->PLL1STAT & (1<<10)));
LPC_SC->PLL1CON = 0x03;
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
#else
LPC_SC->USBCLKCFG = USBCLKCFG_Val;
#endif
LPC_SC->PCONP = PCONP_Val;
LPC_SC->CLKOUTCFG = CLKOUTCFG_Val;
#endif
if (((LPC_SC->PLL0STAT >> 24)&3)==3) {
switch (LPC_SC->CLKSRCSEL & 0x03) {
case 0:
case 3:
SystemFrequency = (IRC_OSC *
((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));
break;
case 1:
//待Pll确定和衔接后PLL0STAT中有M和N,能够计算出实践频率
SystemFrequency = (OSC_CLK *
((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));
break;
case 2:
SystemFrequency = (RTC_CLK *
((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));
break;
}
} else {
switch (LPC_SC->CLKSRCSEL & 0x03) {
case 0:
case 3:
SystemFrequency = IRC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
break;
case 1:
SystemFrequency = OSC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
break;
case 2:
SystemFrequency = RTC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
break;
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/guandian/263218.html