stm32 LED 流水灯剖析(库函数版)
扫描二维码
随时随地手机看文章
基于stm32 F401 discovery 库函数点亮LED 3,4,5,6
一.附原理图一张:分别对应的GPIO为PD12,PD13,PD14,PD15
二.Memory and bus architecture#define PERIPH_BASE((uint32_t)0x40000000) /*!< Peripheral base address in the aliasregion
#define APB1PERIPH_BASEPERIPH_BASE
#define APB2PERIPH_BASE(PERIPH_BASE + 0x00010000)
#define AHB1PERIPH_BASE(PERIPH_BASE + 0x00020000)
#define AHB2PERIPH_BASE(PERIPH_BASE + 0x10000000)
GPIOD在AHB1中,通过
#define GPIOD_BASE (AHB1PERIPH_BASE + 0x0C00)
/*Privatefunctions---------------------------------------------------------*/
/**
*@briefMainprogram
*@paramNone
*@retvalNone
*/
intmain(void)
{
/*! thisisdonethroughSystemInit()functionwhichiscalledfromstartup file(startup_stm32f401xx.s)beforetobranchtoapplicationmain. ToreconfigurethedefaultsettingofSystemInit()function,referto system_stm32f4xx.cfile */ GPIO_InitTypeDefGPIO_InitStructure; /*GPIODPeriphclockenable*/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); /*ConfigurePD12,PD13,PD14andPD15inoutputpushpullmode*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOD,&GPIO_InitStructure); while(1) { /*PD12tobetoggled*/ GPIO_SetBits(GPIOD,GPIO_Pin_12); /*Insertdelay*/ Delay(0x3FFFFF); /*PD13tobetoggled*/ GPIO_SetBits(GPIOD,GPIO_Pin_13); /*Insertdelay*/ Delay(0x3FFFFF); /*PD14tobetoggled*/ GPIO_SetBits(GPIOD,GPIO_Pin_14); /*Insertdelay*/ Delay(0x3FFFFF); /*PD15tobetoggled*/ GPIO_SetBits(GPIOD,GPIO_Pin_15); /*Insertdelay*/ Delay(0x7FFFFF); GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); /*Insertdelay*/ Delay(0xFFFFFF); } } 代码工程资源链接: http://download.csdn.net/detail/xiaoxiaopengbo/9418874