STM32 | 库函数与寄存器开发区别及LED等和按键源码(第三天)

STM32 | STM32F407ZE(LED寄存器开发续第二天源码)

STM32 第三天

一、 库函数与寄存器开发区别

1.1 寄存器

寄存器开发优点

直接操作寄存器,运行效率高。

寄存器开发缺点

1、开发难度大,开发周期长

2、代码可阅读性差,可移植差

3、后期维护难度高

1.2库函数

库函数开优点

1、开发难度较小,开发周期短

2、代码可阅读性强,可移植高

3、后期维护难度低

库函数开缺点

相对于寄存器开发,运行效率略低

注意:库函数其实是ST公司对寄存器的进一步封装。

二、 库函数开发LED

库函数开发LED要添加的库函数文件:stm32f4xx_gpio.c

1、理解led灯原理图

LED0连接在PF9

PF9输出低电平(0),灯亮;PF9输出高电平(0),灯灭;

2、打开GPIOF组时钟

在STM32芯片中,所有的外设时钟是不打开,为了降低功耗

//打开GPIOF组时钟  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);

3、设置PF9灯为输出模式  输出推挽 上拉 速度(50MHZ)

// stm32f4xx_gpio.htypedef struct{
    uint32_t GPIO_Pin;              /*!< Specifies the GPIO pins to be configured.                                       This parameter can be any value of @ref GPIO_pins_define */  GPIOMode_TypeDef GPIO_Mode;     /*!< Specifies the operating mode for the selected pins.                                       This parameter can be a value of @ref GPIOMode_TypeDef */  GPIOSpeed_TypeDef GPIO_Speed;   /*!< Specifies the speed for the selected pins.                                       This parameter can be a value of @ref GPIOSpeed_TypeDef */  GPIOOType_TypeDef GPIO_OType;   /*!< Specifies the operating output type for the selected pins.                                       This parameter can be a value of @ref GPIOOType_TypeDef */  GPIOPuPd_TypeDef GPIO_PuPd;     /*!< Specifies the operating Pull-up/Pull down for the selected pins.                                       This parameter can be a value of @ref GPIOPuPd_TypeDef */}GPIO_InitTypeDef;
GPIO_InitStruct.GPIO_Pin  = GPIO_Pin_9;    //引脚GP
  • 15
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Qt历险记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值