单片机原理与接口技术应用教案debugO;#endif/*Configurethe systemclocks */1/调用各初始化函数/*RCC Configuration */RCC_ConfigurationO,SysTick_Configuration(O);/*NVICConfiguration*/NVIC_ConfigurationO;GPIO_ConfigurationO;while(1)GPIO_SetBits(GPIOC,GPIO_Pin_4|GPIO_Pin_5GPIO_Pin_6|GPIO_Pin_6);Delay(200);GPIO_ResetBits(GPIOC,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6GPIO_Pin_6);Delay(200);count++;7136
单片机原理与接口技术应用教案 36 debug(); #endif /* Configure the system clocks */ //调用各初始化函数 /* RCC Configuration */ RCC_Configuration(); SysTick_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); GPIO_Configuration(); while(1) { GPIO_SetBits(GPIOC,GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_6); Delay(200); GPIO_ResetBits(GPIOC,GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_6); Delay(200); count++; } }
单片机原理与接口技术应用教案市中市中市中市市市市事学**家**Function Name:RCC_Configuration*Description: Configures thedifferent system clocks* Input: None*Output: None*Return:None事事事事事事***/void RCC_Configuration(void)ErrorStatusHSEStartUpStatus/* RCC system reset(for debug purpose) *RCC_DelnitO);/*EnableHSE*/RCC_HSEConfig(RCC_HSE_ON);/* Wait till HSE is ready */HSEStartUpStatus =RCC_WaitForHSEStartUpOif(HSEStartUpStatus == SUCCESS)/* HCLK = SYSCLK *RCC_HCLKConfig(RCC_SYSCLK_Div1))/*PCLK2=HCLK*/RCC_PCLK2Config(RCC_HCLK_Div1);/*PCLK1=HCLK/2*/37
单片机原理与接口技术应用教案 37 /*************************************************************************** **** * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None **************************************************************************** ***/ void RCC_Configuration(void) { ErrorStatus HSEStartUpStatus; /* 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);/*选择外部的8MHz时钟PLLCLK=8MHz*9=72MHz*RCC_PLLConfig(RCC_PLLSource HSE Div1, RCC_PLLMul 9)/*使能PLL*RCC_PLLCmd(ENABLE);/*等待PLL有效*while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) ==RESET)1/*以PLL为系统时钟源*1RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);/*等待有效*/while(RCC_GetSYSCLKSource( !=0x08)10-净事事*****FunctionName:NVIC_Configuration38
单片机原理与接口技术应用教案 38 RCC_PCLK1Config(RCC_HCLK_Div2); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* 选择外部的8MHz时钟 PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /*使能 PLL */ RCC_PLLCmd(ENABLE); /* 等待PLL有效 */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /*以PLL为系统时钟源 */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* 等待有效 */ while(RCC_GetSYSCLKSource() != 0x08) { } } } /*************************************************************************** **** * Function Name : NVIC_Configuration
单片机原理与接口技术应用教案*Description:ConfiguresVectorTablebaselocation* Input: None*Output: None*Return:None****事串***/void NVIC_Configuration(void)tII NVIC_ InitTypeDef NVIC_InitS tructure;1/编译选择#ifdefVECTTAB RAM中断跳转存储区类型*SettheVectorTablebaselocationat 0x20000000*NVIC_SetVectorTable(NVIC_VectTab_RAM, Ox0)#else/*VECT TABFLASH*//*Set theVectorTablebaselocationat 0x08000000*/NVIC_SetVectorTable(NVIC_VectTab_FLASH, Ox0);#endif/*Configure onebitforpreemption priority*/NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);39
单片机原理与接口技术应用教案 39 * Description : Configures Vector Table base location. * 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 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); } /***************************************************************************
单片机原理与接口技术应用教案事*事**Function Name:GPIO_Configuration* Description: Configures the different GPIO ports.*Input: None*Output: None*Retum: None事事事****/void GPIO_Configuration(void)1GPIO_InitTypeDefGPIOInitStructure;/*定义1个结构体变量*/*打开GPIOC*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);/*可以对PC3-PC5一起初始化*/GPIOInitStructure.GPIOPin=GPIOPin3GPIOPin4GPIOPin5GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz,GPIOInit(GPIOC,&GPIO_InitStructure),/*调用库函数初始化GPIO*-本事事水串***Function Namee: SysTick_Configuration*Description: Configures the SysTick to generate an interrupt each I millisecond40
单片机原理与接口技术应用教案 40 **** * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None **************************************************************************** ***/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* 定义1个结构体变量 */ /* 打开GPIOC */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC ,ENABLE); /* 可以对PC3 - PC5 一起初始化 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* 调用库函数初始化GPIO */ } /*************************************************************************** **** * Function Name : SysTick_Configuration * Description : Configures the SysTick to generate an interrupt each 1 millisecond