修改了一下英倍特板例程,做了个跑马灯小实验,系统时钟用8M*9=72M,每个灯延时常数为0x0B71B00(十进制数12M),用示波器测出刚好是延时1S,说明时钟是12M,可是下面的程序中系统时钟是72M的,是我的理解有误吗?希望高手赐教。 #include "stm32f10x_lib.h" GPIO_InitTypeDef GPIO_InitStructure; ErrorStatus HSEStartUpStatus;
/* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); //void NVIC_Configuration(void); void Delay(vu32 nCount);
int main(void) { #ifdef DEBUG debug(); #endif
/* Configure the system clocks */ RCC_Configuration(); /* NVIC Configuration */ // NVIC_Configuration();
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); while (1) { GPIO_SetBits(GPIOC,GPIO_Pin_0); GPIO_ResetBits(GPIOC,GPIO_Pin_3); Delay(0x0B71B00); //Delay 1S ,12MHZ? GPIO_SetBits(GPIOC,GPIO_Pin_1); GPIO_ResetBits(GPIOC,GPIO_Pin_0); Delay(0x0B71B00); GPIO_SetBits(GPIOC,GPIO_Pin_2); GPIO_ResetBits(GPIOC,GPIO_Pin_1); Delay(0x0B71B00); GPIO_SetBits(GPIOC,GPIO_Pin_3); GPIO_ResetBits(GPIOC,GPIO_Pin_2); Delay(0x0B71B00); } }
void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit();
/* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2);
/* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */ RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } /* Enable GPIOA, GPIOB and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC| RCC_APB2Periph_AFIO, ENABLE); }
void Delay(vu32 nCount) { for(; nCount != 0; nCount--); } |