|
我的初始化程序
/******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { /* RCC system reset(for debug purpose)[¸´Î»RCCÍâΧÉ豸¼Ä´æÆ÷µ½Ä¬Èϸ´Î»Öµ] */ RCC_DeInit(); /* Enable HSE [HSEÕñµ´Æ÷¿ªÆô]*/ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready [µÈ´ýHSEÆô¶¯]*/ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* Enable Prefetch Buffer [Ԥȡ»º³åÇøÔÊÐí]*/ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state[´úÂë2¸öÑÓʱÖÜÆÚ] */ FLASH_SetLatency(FLASH_Latency_2); /* HCLK = SYSCLK [AHBʱÖÓµÈÓÚSYSCLK]*/ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK [APB2ʱÖÓµÈÓÚHCLK]*/ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 [µÍËÙAPB1ʱÖÓµÈÓÚHCLK/2]*/ RCC_PCLK1Config(RCC_HCLK_Div2); /* PLLCLK = 8MHz * 4 = 32 MHz [ÅäÖÃPLLʱÖÓÔ´ºÍ³Ë·¨Òò×Ó][PLLʱÖÓÊäÈëµÈÓÚHSEʱÖÓ][PLL³Ë·¨Òò×ÓÈ¡Öµ4]*/ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_4); /* Enable PLL [ÔÊÐíPLL]*/ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready [µÈ´ýPLLʱÖÓ¾ÍÐ÷]*/ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source [Ñ¡ÔñPLL×÷ΪϵͳʱÖÓ]*/ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source[µÈ´ýPLL±»×÷ΪϵͳʱÖÓ] */ while(RCC_GetSYSCLKSource() != 0x08) { } } /* TIM3 clock enable [TIM3¶¨Ê±Æ÷ÔÊÐí]*/ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE); /* Enable GPIOC clock [ʹÄÜGPIOCʱÖÓ]*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC , ENABLE); } /******************************************************************************* * Function Name : GPIO_Configuration * Description : LEDÊä³öÅäÖà * Input : None * Output : None * Return : None *******************************************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* °ÑPA4-8ÅäÖóÉÊäÈëģʽ */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//GPIO×î¸ßËÙ¶È50MHz GPIO_Init(GPIOA, &GPIO_InitStructure); /* °ÑPC13ÅäÖóÉÊäÈëģʽ */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Ñ¡ÔñGPA4-8¡¢GPC13×÷ΪÍⲿÖжÏÊäÈë */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource4 | GPIO_PinSource5 | GPIO_PinSource6 | GPIO_PinSource7 | GPIO_PinSource8); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); }
/******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures the nested vectored interrupt controller.[ÅäÖÃÖжÏÏòÁ¿±íµÄÆðʼλÖÃ] * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 [ÉèÖÃÖжÏÏòÁ¿±íµÄÆðʼλÖÃ0x20000000]*/ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000[ÉèÖÃÖжÏÏòÁ¿±íµÄÆðʼλÖÃ0x0x08000000] */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif
/* Configure the NVIC Preemption Priority Bits[ÅäÖÃÓÅÏȼ¶×é] */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Enable the TIM4 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI4 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } |
|