STM32 LED water light analysis (library function version)

Publisher:快乐旅行Latest update time:2017-09-16 Source: eefocusKeywords:stm32  LED Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Based on stm32 F401 discovery library function, light up LED 3,4,5,6

1. Attached is a schematic diagram:


The corresponding GPIOs are PD12, PD13, PD14, and PD15.

二.Memory and bus architecture 




#define PERIPH_BASE          ((uint32_t)0x40000000) /*!< Peripheral base address in the aliasregion 

#define APB1PERIPH_BASE      PERIPH_BASE

#define APB2PERIPH_BASE      (PERIPH_BASE + 0x00010000)

#define AHB1PERIPH_BASE      (PERIPH_BASE + 0x00020000)

#define AHB2PERIPH_BASE      (PERIPH_BASE + 0x10000000)

GPIOD in AHB1, through

#define GPIOD_BASE            (AHB1PERIPH_BASE + 0x0C00)

3. Key code attached:


  1. /* Private functions ---------------------------------------------------------*/  

  2.   

  3. /** 

  4.   * @brief  Main program 

  5.   * @param  None 

  6.   * @retval None 

  7.   */  

  8. int main(void)  

  9. {  

  10.   /*!< At this stage the microcontroller clock setting is already configured,  

  11.        this is done through SystemInit() function which is called from startup 

  12.        file (startup_stm32f401xx.s) before to branch to application main. 

  13.        To reconfigure the default setting of SystemInit() function, refer to 

  14.         system_stm32f4xx.c file 

  15.      */  

  16.   GPIO_InitTypeDef  GPIO_InitStructure;  

  17.   

  18.   /* GPIOD Periph clock enable */  

  19.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);  

  20.   

  21.   /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */  

  22.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;  

  23.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;  

  24.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;  

  25.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;  

  26.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;  

  27.   GPIO_Init(GPIOD, &GPIO_InitStructure);  

  28.   

  29.   while (1)  

  30.   {  

  31.     /* PD12 to be toggled */  

  32.     GPIO_SetBits(GPIOD, GPIO_Pin_12);  

  33.       

  34.     /* Insert delay */  

  35.     Delay(0x3FFFFF);  

  36.       

  37.     /* PD13 to be toggled */  

  38.     GPIO_SetBits(GPIOD, GPIO_Pin_13);  

  39.       

  40.     /* Insert delay */  

  41.     Delay(0x3FFFFF);  

  42.     

  43.     /* PD14 to be toggled */  

  44.     GPIO_SetBits(GPIOD, GPIO_Pin_14);  

  45.       

  46.     /* Insert delay */  

  47.     Delay(0x3FFFFF);  

  48.       

  49.     /* PD15 to be toggled */  

  50.     GPIO_SetBits(GPIOD, GPIO_Pin_15);  

  51.       

  52.     /* Insert delay */  

  53.     Delay(0x7FFFFF);  

  54.       

  55.     GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);  

  56.       

  57.     /* Insert delay */  

  58.     Delay(0xFFFFFF);  

  59.   }  

  60. }  


Code Engineering Resource Links:

http://download.csdn.net/detail/xiaoxiaopengbo/9418874


Keywords:stm32  LED Reference address:STM32 LED water light analysis (library function version)

Previous article:stm32 startup process
Next article:STM32 NVIC preemption priority and response priority

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号