調(diào)試LPC1768, NXP的庫好像不如Luminary的好用(大家都這么說,也就跟著人云亦云了)。對照LPC1768的手冊看了看Keil例程的PLL0配置過程,記錄如下:
本文引用地址:http://cafeforensic.com/article/201611/319423.htm
#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,所以除數(shù)為N+1=6
// 0x63為乘數(shù)M,M+1=100,記得要把16進(jìn)制換算為10進(jìn)制
//Fcco = 2*100*12/6 = 400,然后再除以CPU clock的4,即該設(shè)置主頻為100M
LPC_SC->PLL0CFG = PLL0CFG_Val;
LPC_SC->PLL0CON = 0x01;
//確認(rèn)序列
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,可以計算出實(shí)際頻率
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;
}
}
評論