1.定义GPIO初始化结构体
GPIO_InitTypeDef GPIO_InitStructure;
2.打开GPIO时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
3.GPIO具体寄存器配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
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_UP;
4.GPIO初始化
GPIO_Init(GPIOF, &GPIO_InitStructure);
5.GPIO使用
可以使用位带操作写0或写1
也可以使用GPIO_SetBits和GPIO_ResetBits函数
GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);
GPIO_ResetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);