STM32 V5 source code
guowenxue
2018-02-04 785deec23b4cb1e7c4c4d81eb808f195adb1d98a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/****************************************************************************
*   Copyright: (C)2014 Î人ÁèÔÆÇ¶ÈëʽʵÑéÊÒ www.emblinux.com
*      Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
* Description: ·Ü¶·STM32v5¿ª·¢°åcontiki²Ù×÷ϵͳLEDÉ豸²Ù×÷º¯Êý½Ó¿Ú
*   ChangeLog:
*        °æ±¾ºÅ     ÈÕÆÚ       ×÷Õß      ËµÃ÷
*        V1.0.0  2014.08.25  GuoWenxue   ·¢²¼¸Ã°æ±¾
****************************************************************************/
 
#include "stm32v5_led.h"
 
static led_gpio_t   leds_gpio[MAX_LED] =
{
        {LED1, GPIOB, GPIO_Pin_5}, /* LED1 ÓõÄGPB5 */
        {LED2, GPIOD, GPIO_Pin_6}, /* LED2 ÓõÄGPD6 */
        {LED3, GPIOD, GPIO_Pin_3}, /* LED3 ÓõÄGPD3 */        
};
 
 
void init_led_gpio(void)
{
    int                i;
    GPIO_InitTypeDef   GPIO_InitStructure;
 
    /* Ê¹ÄÜPBºÍPD×é GPIOµÄʱÖÓ */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD , ENABLE);    
    
    /*ÉèÖàPB5(LED1), PD6(LED2), PD3(LED3)Ϊ GPIO Êä³öÍÆÃâģʽ£¬¿ÚÏß·­×ªËÙ¶ÈΪ50MHz */
    for(i=0; i<MAX_LED; i++)
    {
        /*ÉèÖàPB5(LED1)Ϊ GPIO Êä³öÍÆÃâģʽ£¬¿ÚÏß·­×ªËÙ¶ÈΪ50MHz */
        GPIO_InitStructure.GPIO_Pin = leds_gpio[i].pin;                     
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(leds_gpio[i].group, &GPIO_InitStructure);                        
  }
}
 
void turn_led(int which, int cmd)
{
   if(which<0 || which> MAX_LED )
         return;
     
     if(OFF == cmd)
         GPIO_ResetBits(leds_gpio[which].group, leds_gpio[which].pin);
     else
         GPIO_SetBits(leds_gpio[which].group, leds_gpio[which].pin);
}