读懂数据手册,根据数据手册实现功能代码

固件库点灯

main.c

void delay(uint32_t count)
{
	for(;count!=0;count--);
	

}

int main(void)
{
	/*在这里添加自己的程序*/
	
	LED_GPIO_Config();
	
	while(1)
	{
		/*流水灯*/
		/*
		GPIO_ResetBits(GPIOF,GPIO_Pin_6);
		delay(0xffffff);
		GPIO_SetBits(GPIOF,GPIO_Pin_6);
		
		GPIO_ResetBits(GPIOF,GPIO_Pin_7);
		delay(0xffffff);
		GPIO_SetBits(GPIOF,GPIO_Pin_7);
		
		GPIO_ResetBits(GPIOF,GPIO_Pin_8);
		delay(0xffffff);
		GPIO_SetBits(GPIOF,GPIO_Pin_8);
		*/
		
		/*三种灯一块亮*/
		/*
		GPIO_ResetBits(GPIOF,GPIO_Pin_6);
		delay(0xffffff);
		GPIO_ResetBits(GPIOF,GPIO_Pin_7);
		delay(0xffffff);
		GPIO_ResetBits(GPIOF,GPIO_Pin_8);
		*/
	}
}

bsp_led.c

#include "bsp_led.h"
#include "stm32f4xx_gpio.h"

void LED_GPIO_Config(void)
{
	/*第一步:打开外设的时钟*/
	 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
	
	/*第二步:定义一个GPIO初始化结构体*/
	GPIO_InitTypeDef GPIO_InitStruct;
	
	/*第三步:配置GPIO初始化结构体的成员*/
	GPIO_InitStruct.GPIO_Pin =	GPIO_Pin_6;//选择要控制的GPIO引脚
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;//设置引脚模式为输出模式
	GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;//设置引脚的输出类型为推挽输出
	GPIO_InitStruct.GPIO_Speed = GPIO_Low_Speed;	//设置引脚速率为2MHZ->low
	GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; //设置引脚为上拉模式

	/*第四步:调用GPIO初始化函数,将配置好的结构体成员的额参数写入寄存器*/
	GPIO_Init(GPIOF,&GPIO_InitStruct);
	GPIO_ResetBits(GPIOF,GPIO_Pin_6);
	
	GPIO_InitStruct.GPIO_Pin =	GPIO_Pin_7;
	GPIO_Init(GPIOF,&GPIO_InitStruct);
	
	GPIO_InitStruct.GPIO_Pin =	GPIO_Pin_8;
	GPIO_Init(GPIOF,&GPIO_InitStruct);
}

按键->点灯灭灯->扫描按键按下

main.c

#include "bsp_key.h"
#include "bsp_led.h"

void delay(uint32_t count)
{
	for(;count!=0;count--);
}

int main(void)
{
	/*
		LED_GPIO_Config();
	KEY_GPIO_Config();
	while(1)
	{
		if(Key_Scan(GPIOA,GPIO_Pin_0) ==KEY_ON)
		{
			delay(0x3fffff);
			if(Key_Scan(GPIOA,GPIO_Pin_0)==KEY_ON)
			{
				LED1_TOGGLE;
			}
		}
		if(Key_Scan(GPIOC,GPIO_Pin_13) ==KEY_ON)
		{
			delay(0x3fffff);
			if(Key_Scan(GPIOC,GPIO_Pin_13) ==KEY_ON)
			{
				LED2_TOGGLE;
			}
		}
	}
	*/

}

bsp_key.c

#include "bsp_key.h" 


void KEY_GPIO_Config(void)
{	
	/*第一步:打开GPIO的时钟*/
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOC,ENABLE);
	
	/*第二步:定义一个GPIO初始化结构体*/
	GPIO_InitTypeDef GPIO_InitStruct;
	
	/*第三步:配置GPIO初始化结构体的成员*/
	GPIO_InitStruct.GPIO_Pin =	GPIO_Pin_0;//选择要控制的GPIO引脚
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;//设置引脚模式为输出模式
//GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;//设置引脚的输出类型为推挽输出
//GPIO_InitStruct.GPIO_Speed = GPIO_Low_Speed;	//设置引脚速率为2MHZ->low
	GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; //设置引脚为上拉模式

	/*第四步:调用GPIO初始化函数,将配置好的结构体成员的额参数写入寄存器*/
	GPIO_Init(GPIOA,&GPIO_InitStruct);
	
	
	
	/*第三步:配置GPIO初始化结构体的成员*/
	GPIO_InitStruct.GPIO_Pin =	GPIO_Pin_13;//选择要控制的GPIO引脚
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;//设置引脚模式为输出模式
//GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;//设置引脚的输出类型为推挽输出
//GPIO_InitStruct.GPIO_Speed = GPIO_Low_Speed;	//设置引脚速率为2MHZ->low
	GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; //设置引脚为上拉模式

	/*第四步:调用GPIO初始化函数,将配置好的结构体成员的额参数写入寄存器*/
	GPIO_Init(GPIOC,&GPIO_InitStruct);
}


uint8_t Key_Scan(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin)
{
	if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY_ON)
	{
		while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY_ON)
		return KEY_ON;
	}
	else	return KEY_OFF;
}
	

bsp_led.c

#include "bsp_led.h"   


void LED_GPIO_Config(void)
{		
		/*定义一个GPIO_InitTypeDef类型的结构体*/
		GPIO_InitTypeDef GPIO_InitStructure;

		/*开启LED相关的GPIO外设时钟*/
		RCC_AHB1PeriphClockCmd ( LED1_GPIO_CLK|
	                           LED2_GPIO_CLK|
	                           LED3_GPIO_CLK, ENABLE); 

		/*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED1_PIN;	

		/*设置引脚模式为输出模式*/
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   
    
    /*设置引脚的输出类型为推挽输出*/
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    
    /*设置引脚为上拉模式*/
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

		/*设置引脚速率为2MHz */   
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 

		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
		GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStructure);	
    
    /*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED2_PIN;	
    GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStructure);	
    
    /*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED3_PIN;	
    GPIO_Init(LED3_GPIO_PORT, &GPIO_InitStructure);	
		
		/*关闭RGB灯*/
		LED_RGBOFF;		
}

RCC.寄存器->实现闪烁

main.c

#include "stm32f4xx.h"
#include "./led/bsp_led.h"
#include "bsp_clkconfig.h"

void Delay(__IO u32 nCount); 

/**
  * @brief  主函数
  * @param  无
  * @retval 无
  */
int main(void)
{
	/*程序来到这里的时候,系统的时钟已经由SystemInit这个函数初始化好了*/
	User_SetSysClock();
	//将startup_stm32f40xx.s中系统时钟初始化函数注释掉,系统自动使用HSI作为系统时钟
	
	/* LED 端口初始化 */
	LED_GPIO_Config();

	/* 控制LED灯 */
	while (1)
	{
		 
		LED1(ON);
		Delay(0xffffff);
		LED1(OFF);
		Delay(0Xffffff);
	
	}

}

void Delay(__IO uint32_t nCount)	 //简单的延时函数
{
	for(; nCount != 0; nCount--);
}

bsp_clkconfig.c

void User_SetSysClock(void)
{
	RCC_DeInit();//复位RCC的所有寄存器
/******************************************************************************/
/*            PLL (clocked by HSE) used as System clock source                */
/******************************************************************************/
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  
  /* Enable HSE */	//使能HSE
  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 
  /* Wait till HSE is ready and if Time out is reached exit */
	/*等待HSE启动稳定,如果超时则推出*/
  do
  {
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
    StartUpCounter++;
  } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));

  if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  {
    HSEStatus = (uint32_t)0x01;
  }
  else
  {
    HSEStatus = (uint32_t)0x00;
  }
	/*HSE 启动成功*/
  if (HSEStatus == (uint32_t)0x01)
  {
    /* Select regulator voltage output Scale 1 mode */
    /*选择电压调节器的模式为1*/
		RCC->APB1ENR |= RCC_APB1ENR_PWREN;
    PWR->CR |= PWR_CR_VOS;
		
    /* HCLK = SYSCLK / 1*/
    RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
    /* PCLK2 = HCLK / 2*/
    RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; 
    /* PCLK1 = HCLK / 4*/
    RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
    /* Configure the main PLL */
    /*配置主PLL*/
//		RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
//                   (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
			RCC->PLLCFGR = 25 | (336 << 6) | (((2 >> 1) -1) << 16) |
                   (RCC_PLLCFGR_PLLSRC_HSE) | (7 << 24);
    /* Enable the main PLL */
		/*使能主PLL,使能后参数不能更改*/
    RCC->CR |= RCC_CR_PLLON;
    /* Wait till the main PLL is ready */
		/*等待主PLL稳定*/
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
    {
    }  
    /* Configure Flash prefetch, Instruction cache, Data cache and wait state */
    /*配置FLASH预取指,指令缓存,数据缓存,等待周期*/
		FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
    /* Select the main PLL as system clock source */
    /*选择PLL时钟为系统时钟*/
		RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
    RCC->CFGR |= RCC_CFGR_SW_PLL;
    /* Wait till the main PLL is used as system clock source */
    /*确保主PLL时钟选为系统时钟*/
		while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
    {
    }
  }
  else
  { /* If HSE fails to start-up, the application will have wrong clock
         configuration. User can add here some code to deal with this error */
		/*HSE启动失败,在这里添加启动失败的处理代码*/
	}
}

bsp_led.c

#include "./led/bsp_led.h"   

 /**
  * @brief  初始化控制LED的IO
  * @param  无
  * @retval 无
  */
void LED_GPIO_Config(void)
{		
		/*定义一个GPIO_InitTypeDef类型的结构体*/
		GPIO_InitTypeDef GPIO_InitStructure;

		/*开启LED相关的GPIO外设时钟*/
		RCC_AHB1PeriphClockCmd ( LED1_GPIO_CLK|
	                           LED2_GPIO_CLK|
	                           LED3_GPIO_CLK, ENABLE); 
		/*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED1_PIN;	
		/*设置引脚模式为输出模式*/
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   
    /*设置引脚的输出类型为推挽输出*/
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;  
    /*设置引脚为上拉模式*/
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
		/*设置引脚速率为2MHz */   
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
		GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStructure);	   
    /*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED2_PIN;	
    GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStructure);	    
    /*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED3_PIN;	
    GPIO_Init(LED3_GPIO_PORT, &GPIO_InitStructure);			
		/*关闭RGB灯*/
		LED_RGBOFF;		
}

RCC.固件库->实现闪烁

main.c

#include "./led/bsp_led.h"
#include "bsp_clkconfig.h"

void Delay(__IO u32 nCount); 

/**
  * @brief  主函数
  * @param  无
  * @retval 无
  */
int main(void)
{
	/*程序来到这里的时候,系统的时钟已经由SystemInit这个函数初始化好了*/
	//User_SetSysClock();
	/*如果开发板的外部晶振不是25M时,修改第一个形参M*/
//HSE_SetSysClock(25,336,2,7);
	HSI_SetSysClock(16, 336, 2, 7);

	//将startup_stm32f40xx.s中系统时钟初始化函数注释掉,系统自动使用HSI作为系统时钟
	
	/* LED 端口初始化 */
	LED_GPIO_Config();
	
	MCO1_GPIO_Config();
	MCO2_GPIO_Config();
	
  RCC_MCO1Config(RCC_MCO1Source_PLLCLK, RCC_MCO1Div_1);
  RCC_MCO2Config(RCC_MCO2Source_SYSCLK, RCC_MCO2Div_1);

	/* 控制LED灯 */
	while (1)
	{
		LED1(ON);
		Delay(0xfffff);
		LED1(OFF);
		Delay(0Xfffff);
	}
}

void Delay(__IO uint32_t nCount)	 //简单的延时函数
{
	for(; nCount != 0; nCount--);
}

bsp_clkconfig.c

#include "bsp_clkconfig.h"
#include "stm32f4xx.h"

void User_SetSysClock(void)
{
	RCC_DeInit();//复位RCC的所有寄存器
/******************************************************************************/
/*            PLL (clocked by HSE) used as System clock source                */
/******************************************************************************/
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  
  /* Enable HSE */	//使能HSE
  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 
  /* Wait till HSE is ready and if Time out is reached exit */
	/*等待HSE启动稳定,如果超时则推出*/
  do
  {
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
    StartUpCounter++;
  } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));

  if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  {
    HSEStatus = (uint32_t)0x01;
  }
  else
  {
    HSEStatus = (uint32_t)0x00;
  }
	/*HSE 启动成功*/
  if (HSEStatus == (uint32_t)0x01)
  {
    /* Select regulator voltage output Scale 1 mode */
    /*选择电压调节器的模式为1*/
		RCC->APB1ENR |= RCC_APB1ENR_PWREN;
    PWR->CR |= PWR_CR_VOS;
		
    /* HCLK = SYSCLK / 1*/
    RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
    /* PCLK2 = HCLK / 2*/
    RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; 
    /* PCLK1 = HCLK / 4*/
    RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
    /* Configure the main PLL */
    /*配置主PLL*/
//		RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
//                   (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
			RCC->PLLCFGR = 25 | (336 << 6) | (((2 >> 1) -1) << 16) |
                   (RCC_PLLCFGR_PLLSRC_HSE) | (7 << 24);
    /* Enable the main PLL */
		/*使能主PLL,使能后参数不能更改*/
    RCC->CR |= RCC_CR_PLLON;
    /* Wait till the main PLL is ready */
		/*等待主PLL稳定*/
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
    {}  
    /* Configure Flash prefetch, Instruction cache, Data cache and wait state */
    /*配置FLASH预取指,指令缓存,数据缓存,等待周期*/
		FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
    /* Select the main PLL as system clock source */
    /*选择PLL时钟为系统时钟*/
		RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
    RCC->CFGR |= RCC_CFGR_SW_PLL;
    /* Wait till the main PLL is used as system clock source */
    /*确保主PLL时钟选为系统时钟*/
		while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
    {}
  }
  else
  { /* If HSE fails to start-up, the application will have wrong clock
         configuration. User can add here some code to deal with this error */
		/*HSE启动失败,在这里添加启动失败的处理代码*/
	}
}

void HSE_SetSysClock(uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
{
	ErrorStatus HSE_ErrorStatus = ERROR;
	RCC_DeInit();
  /* Enable HSE */	//使能HSE
	RCC_HSEConfig(RCC_HSE_ON);
	HSE_ErrorStatus	= RCC_WaitForHSEStartUp();	
	if(HSE_ErrorStatus == SUCCESS)
	{
    /*选择电压调节器的模式为1*/
		RCC->APB1ENR |= RCC_APB1ENR_PWREN;
    PWR->CR |= PWR_CR_VOS;
		RCC_HCLKConfig(RCC_SYSCLK_Div1);
		RCC_PCLK1Config(RCC_SYSCLK_Div4);
		RCC_PCLK2Config(RCC_HCLK_Div2);
		RCC_PLLConfig(RCC_PLLSource_HSE, PLLM, PLLN, PLLP, PLLQ);
		RCC_PLLCmd(ENABLE);		
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
		{}		
		/*配置FLASH预取指,指令缓存,数据缓存,等待周期*/
		FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; 
		/*选择PLL时钟为系统时钟*/
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		while(RCC_GetSYSCLKSource() != 0x08)
		{}
	}
	else
	{
		/*HSE启动失败,在这里添加启动失败的代码*/		
	}
}

void MCO1_GPIO_Config(void)
{
	/*定义一个GPIO_InitTypeDef类型的结构体*/
		GPIO_InitTypeDef GPIO_InitStructure;
		/*开启LED相关的GPIO外设时钟*/
		RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA, ENABLE); 
		/*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;	
		/*设置引脚模式为输出模式*/
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;      
    /*设置引脚的输出类型为推挽输出*/
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;   
    /*设置引脚为上拉模式*/
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
		/*设置引脚速率为2MHz */   
		GPIO_InitStructure.GPIO_Speed = GPIO_High_Speed; 
		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
		GPIO_Init(GPIOA, &GPIO_InitStructure);	   
}

void MCO2_GPIO_Config(void)
{
	/*定义一个GPIO_InitTypeDef类型的结构体*/
		GPIO_InitTypeDef GPIO_InitStructure;
		/*开启LED相关的GPIO外设时钟*/
		RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOC, ENABLE); 
		/*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;	
		/*设置引脚模式为输出模式*/
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;      
    /*设置引脚的输出类型为推挽输出*/
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;   
    /*设置引脚为上拉模式*/
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
		/*设置引脚速率为2MHz */   
		GPIO_InitStructure.GPIO_Speed = GPIO_High_Speed; 
		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
		GPIO_Init(GPIOC, &GPIO_InitStructure);	
    
}

void HSI_SetSysClock(uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
{
	volatile uint32_t HSI_ErrorStatus = 0;
	RCC_DeInit();
  /* Enable HSE */	
	//使能HSI
	RCC_HSICmd(ENABLE);	
	HSI_ErrorStatus = RCC->CR & RCC_CR_HSIRDY;	
	if(HSI_ErrorStatus == RCC_CR_HSIRDY)
	{
    /*选择电压调节器的模式为1*/
		RCC->APB1ENR |= RCC_APB1ENR_PWREN;
    PWR->CR |= PWR_CR_VOS;
		RCC_HCLKConfig(RCC_SYSCLK_Div1);
		RCC_PCLK1Config(RCC_SYSCLK_Div4);
		RCC_PCLK2Config(RCC_HCLK_Div2);	
		RCC_PLLConfig(RCC_PLLSource_HSI, PLLM, PLLN, PLLP, PLLQ);		
		RCC_PLLCmd(ENABLE);		
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
		{}		
		/*配置FLASH预取指,指令缓存,数据缓存,等待周期*/
		FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
		/*选择PLL时钟为系统时钟*/
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		while(RCC_GetSYSCLKSource() != 0x08)
		{}
	}
	else
	{
		/*HSI启动失败,在这里添加启动失败的代码*/	
	}
}

bsp_led.c

#include "./led/bsp_led.h"   

 /**
  * @brief  初始化控制LED的IO
  * @param  无
  * @retval 无
  */
void LED_GPIO_Config(void)
{		
		/*定义一个GPIO_InitTypeDef类型的结构体*/
		GPIO_InitTypeDef GPIO_InitStructure;

		/*开启LED相关的GPIO外设时钟*/
		RCC_AHB1PeriphClockCmd ( LED1_GPIO_CLK|
	                           LED2_GPIO_CLK|
	                           LED3_GPIO_CLK, ENABLE); 

		/*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED1_PIN;	

		/*设置引脚模式为输出模式*/
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   
    
    /*设置引脚的输出类型为推挽输出*/
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    
    /*设置引脚为上拉模式*/
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

		/*设置引脚速率为2MHz */   
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 

		/*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
		GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStructure);	
    
    /*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED2_PIN;	
    GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStructure);	
    
    /*选择要控制的GPIO引脚*/															   
		GPIO_InitStructure.GPIO_Pin = LED3_PIN;	
    GPIO_Init(LED3_GPIO_PORT, &GPIO_InitStructure);	
		
		/*关闭RGB灯*/
		LED_RGBOFF;		
}