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)
...........................
}