void RCC_Configuration(void)

void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
    RCC_DeInit();  //时钟管理重置  /* RCC system reset(for debug purpose) */
    RCC_HSEConfig(RCC_HSE_ON); //打开外部晶振  //Enable HSE
    HSEStartUpStatus = RCC_WaitForHSEStartUp();  //等待外部晶振就绪  //Wait till HSE is ready
    if(HSEStartUpStatus == SUCCESS)
    {
        RCC_HCLKConfig(RCC_SYSCLK_Div1);    //AHB使用系统时钟   //HCLK = SYSCLK
        RCC_PCLK2Config(RCC_HCLK_Div1);     //APB2为HCLK/1      //PCLK2 = HCLK/1
        RCC_PCLK1Config(RCC_HCLK_Div2);     //APB1为HCLK/2      //PCLK1 = HCLK/2
        RCC_ADCCLKConfig(RCC_PCLK2_Div4);   //设置ADC时钟频率
        //注:AHB主要负责外部存储器时钟。PB2负责AD,I/O,高级TIM,串口1。APB1负责DA,USB,SPI,I2C,CAN,串口2345,普通TIM。
        FLASH_SetLatency(FLASH_Latency_2);  //flash操作的延时   //Flash 2 wait state
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);   //flash读取缓冲,加速 //Enable Prefetch Buffer
     
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);  //PLLCLK = 8MHz * 9 = 72MHz
        RCC_PLLCmd(ENABLE);  //启动PLL //Enable PLL
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) //等待PLL启动  /* Wait till PLL is ready */
        {
        }
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //将PLL设置为系统时钟源  /* Select PLL as system clock source */
        while(RCC_GetSYSCLKSource() != 0x08)           //等待系统时钟源的启动  /* Wait till PLL is used as system clock source */
        {
        }
    }
为下面每一行代码添加注释:#include "stm32f10x.h" void RCC_Configuration(void) { /* Enable GPIOA, GPIOC and AFIO clocks / RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); / Enable SYSCFG clock / RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; / Configure PA0 pin as input floating / GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); / Configure PC13 pin as output push-pull / GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); } void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure / Configure the NVIC Preemption Priority Bits / NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); / Enable the EXTI0 Interrupt / NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXTI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; / Configure EXTI Line0 to generate an interrupt on falling edge / EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); / Connect EXTI Line0 to PA0 pin / GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); } void SysTick_Configuration(void) { / Configure SysTick to generate an interrupt every 1ms / if (SysTick_Config(SystemCoreClock / 1000)) { / Capture error / while (1); } } void Delay(__IO uint32_t nTime) { / Wait for nTime millisecond / TimingDelay = nTime; while (TimingDelay != 0); } void TimingDelay_Decrement(void) { if (TimingDelay != 0x00) { TimingDelay--; } } int main(void) { RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration(); EXTI_Configuration(); SysTick_Configuration(); / Infinite loop / while (1) { / Toggle PC13 LED every 500ms / GPIOC->ODR ^= GPIO_Pin_13; Delay(500); } } void EXTI0_IRQHandler(void) { / Check if PA0 button is pressed / if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == RESET) { / Reset MCU / NVIC_SystemReset(); } / Clear EXTI Line0 pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); }
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值