栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【STM32】固件库点灯

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【STM32】固件库点灯

  1. 固件点灯
  • 在User目录下创建一个文件夹命名为led文件夹中包含led.c、led.h

  • 打开工程在工程文件中User目录下添加led.c——并在led.c中包含led.h的头文件编译运行就会自动生成led.h文件

三、led.c中封装要实现的函数 led.h中声明函数然后就可以在主函数中调用函数!

  • 在32中要点亮一个led灯有三个步骤
  1. 使能APB2的时钟GPIOC(rcc.h)

RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);

uint32_t RCC_APB2Periph:外设                     RCC_APB2Periph_GPIOC

FunctionalState NewState:状态(要么0要么1)     ENABLE

总:RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

2.配置结构体(gpio.h)

GPIO_InitTypeDef led_init; 声明结构体名字

led_init.GPIO_Mode      =     模式;      GPIO_Mode_Out_PP:推挽输出

led_init.GPIO_Pin        =     引脚;  GPIO_Pin_13:第13引脚

led_init.GPIO_Speed     =     频率;      GPIO_Speed_10MHz:10MHz

GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);

GPIO_TypeDef* GPIOx:GPIOC

GPIO_InitTypeDef* GPIO_InitStruct:&led_init(因为为指针类型所以&)

总:

GPIO_InitTypeDef led_init;

       led_init.GPIO_Mode      =     GPIO_Mode_Out_PP;

       led_init.GPIO_Pin          =     GPIO_Pin_13;

       led_init.GPIO_Speed     =     GPIO_Speed_10MHz;

      

       GPIO_Init(GPIOC, &led_init);

实现点灯:

因为D2 PC13为低电平触发所以给PC13一个低电平

void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

GPIO_TypeDef* GPIOx:GPIOC

uint16_t GPIO_Pin:GPIO_Pin_13

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/966004.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号