当前位置:首页 > 单片机 > 单片机
[导读]基于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 addres

基于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


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭