菜鸟之学习STM32之GPIO输出之入门

本文介绍了使用GPIO进行LED灯控制,包括开启APB2总线时钟、GPIO初始化设置以及LED灯的点亮操作。随后展示了如何使用GPIO实现流水灯的循环点亮。
摘要由CSDN通过智能技术生成

1.GPIO之led灯点亮

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//开启APB2总线外设时钟命令

只有APB2总线上挂有GPIO
    GPIO_InitTypeDef GPIO_InitStruct;//给结构体GPIO_InitTypeDef 重新命名

typedef struct
{
  uint16_t GPIO_Pin;             /*!< Specifies the GPIO pins to be configured.指定的引脚被配置
                                      This parameter can be any value of @ref GPIO_pins_define */

  GPIOSpeed_TypeDef GPIO_Speed;  /*!< Specifies the speed for the selected pins.指定被配置的引脚速度。
                                      This parameter can be a value of @ref GPIOSpeed_TypeDef */

  GPIOMode_TypeDef GPIO_Mode;    /*!< Specifies the operating mode for the selected pins.指定引脚的工作模式(前文提到的八种类型 )
                                      This parameter can be a value of @ref GPIOMode_TypeDef */
}GPIO_InitTypeDef; //结构体名字


    GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;//输出模式为推晚输出
    GPIO_InitStruct.GPIO_Pin=GPIO_Pin_13;//引脚13
    GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;//引脚速度50MHZ
    GPIO_Init(GPIOA,&GPIO_InitStruct); //初始化GPIOA  将结构体参数配置到GPIOA中
    GPIO_SetBits(GPIOA,GPIO_Pin_13);//设置13引脚为高电平
    GPIO_ResetBits(GPIOA,GPIO_Pin_13);//设置13引脚为低电平

关键词:RCC_APB2periphClockCMD 参数 RCC_APB2periph_GPIOx

              typedef struct{

typedef enum1

typedef enum2

........

}结构体名字

2.GPIO之流水灯点亮

while(1){

GPIO_Write(GPIOA,~0X0001)//  * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.
//  * @param  PortVal: specifies the value to be written to the port output data register.

             //GPIOx->ODR = PortVal;  ORD输出寄存器

GPIO_Write(GPIOA,~0X0002)

...........................

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值