说明:(只要是有关引脚的功能必须先配置GPIO 端口) 一
对于GPIO 编程 步骤:1
使能IO 口时钟
调用函数为 RCC_APB2PeriphClockCmd();(注意:结构体申明必须放在使能时钟语句之前) 2
初始化 IO 口参数
调用函数 GPIO_Init(); 3
#include "led
h" void LED_Init(void) { //PB
5 GPIO_InitTypeDef GPIO_InitStructure; //定义GPIO 的初始化结构体 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD, ENABLE);//使能相应的引脚时钟 /*******GPIO 结构体中的三个参数赋值********************/ GPIO_InitStructure
GPIO_Pin= GPIO_Pin_5; GPIO_InitStructure
GPIO_Speed= GPIO_Speed_50MHz; GPIO_InitStructure
GPIO_Mode= GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIO 引脚PB
5 //PD
6 | PD
3 GPIO_InitStructure
GPIO_Pin= GPIO_Pin_6 | GPIO_Pin_3; GPIO_InitStructure
GPIO_Speed= GPIO_Speed_50MHz; GPIO_InitStructure
GPIO_Mode= GPIO_Mode_Out_PP; GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化PD