本文引用地址:http://m.butianyuan.cn/article/201611/322895.htmRCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//配置系統(tǒng)時(shí)鐘為PLL
while(RCC_GetSYSCLKSource()!=0x08)//檢查系統(tǒng)時(shí)鐘是否為PLL
{
}
}
else
{
while(1)
{
}
}
}
voidSetSysClockTo36(void)//設(shè)置系統(tǒng)時(shí)鐘為36MHz函數(shù)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_1);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div1);
RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9);//8/2*9=36設(shè)置PLL為36MHz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}
else
{
while(1)
{
}
}
}
voidSetSysClockTo48(void)//設(shè)置系統(tǒng)時(shí)鐘為48MHz函數(shù)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_1);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_6);//設(shè)置PLL為48MHz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}
else
{
while(1)
{
}
}
}
voidSetSysClockTo72(void)//設(shè)置系統(tǒng)時(shí)鐘為72MHz
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);//設(shè)置PLL為72MHz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}
else
{
while(1)
{
}
}
}
voidNVIC_Configuration(void)//設(shè)置中斷向量表基址
{
NVIC_InitTypeDefNVIC_InitStructure;//NVIC初始化結(jié)構(gòu)體,定義初始化NVIC的結(jié)構(gòu)體變量
#ifdefVECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
//NVIC_InitStructure是前面定義的NVIC初始化結(jié)構(gòu)體包括以下幾項(xiàng)
NVIC_InitStructure.NVIC_IRQChannel=RCC_IRQChannel;//指定IRQ通道這里指定為RCC全局中斷
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//該參數(shù)設(shè)置成員NVIC_IRQChannel中的先占優(yōu)先級(jí)
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;//該參數(shù)設(shè)置成員NVIC_IRQChannel中的從優(yōu)先級(jí)詳見(jiàn)函數(shù)說(shuō)明P167
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//該參數(shù)指定在成員NVIC_IRQChannel中定義的IRQ通道被使能還是失能
//取值可以為ENABLE或DISABLE
NVIC_Init(&NVIC_InitStructure);//根據(jù)結(jié)構(gòu)體NVIC_InitStructure中指定的參數(shù)初始化外設(shè)NVIC
}
voidDelay(vu32nCount)
{
for(;nCount!=0;nCount--);
}
#ifdefDEBUG
//assert_failed編寫(xiě)于文件main.c或其他用戶C文件中
voidassert_failed(u8*file,u32line)
{
while(1)
{
}
}
#endif
評(píng)論