#define XTAL_FREQ 12000000
#define VECT_TAB_OFFSET 0x0000
void SystemInit(void)
{
//PLL0时钟配置
LPC_SC->SCS = 0X00000020; /*使能外部主晶振,频率范围1-20M*/
if (LPC_SC->SCS & (1 << 5)) /* 主时钟被使能 */
{
while ((LPC_SC->SCS & (1<<6)) == 0);/* 等待主晶振使能并稳定 */
}
LPC_SC->CCLKCFG = 0x00000003; /* 选择PLL到CCLK的分频 4 */
LPC_SC->PCLKSEL0 = 0x00000000; /*选择外设时钟从CCLK的分屏 均为0,均为4分频率,后期可改 */
LPC_SC->PCLKSEL1 = 0x00000000;
LPC_SC->CLKSRCSEL = 0x00000001; /* 选择CCLK时钟源 主震荡器作为PLL0时钟源 */
LPC_SC->PLL0CFG = 0x00050063; /* 选择PLL倍频 N 6 M 100 pllout 400M */
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
LPC_SC->PLL0CON = 0x01; /* 使能PLL0 */
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & (1<<26)));/* 等待PLL0锁定 */
LPC_SC->PLL0CON = 0x03; /* 使能PLL0连接并使能 */
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* 等待连接并使能成功 */
//PLL1时钟配置
LPC_SC->PLL1CFG = 0x00000023; /*设置PLL1分频 M 3 P 2 */
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
LPC_SC->PLL1CON = 0x01; /* PLL1 Enable */
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
while (!(LPC_SC->PLL1STAT & (1<<10)));/* 等待PLL时钟锁定 */
LPC_SC->PLL1CON = 0x03; /* 使能并连接 */
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
while (!(LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));/* 等待连接并使能成功 */
LPC_SC->PCONP = 0x00000008; /* 初始化仅仅打开UART0时钟 */
LPC_SC->CLKOUTCFG = 0x00000000; /* 不使用CLOCK输出 */
LPC_SC->FLASHCFG = 0x0000403A; //设置flash访问时间
#if (__RAM_MODE__==1) //根据配置
SCB->VTOR = 0x10000000 | VECT_TAB_OFFSET;
#else
SCB->VTOR = 0x00000000 | VECT_TAB_OFFSET; //中断向量表在flash区间,偏移为0
#endif
}