步骤:
1 首先进行引脚定义
1.1 定义端口
1.2 定义端口引脚
1.3 定义端口时钟
#define LED_G_GPIO_PORT GPIOB /* GPIO端口 */
#define LED_G_GPIO_CLK RCC_APB2Periph_GPIOB /* GPIO端口时钟 */
#define LED_G_GPIO_PIN GPIO_Pin_0 /* 连接到SCL时钟线的GPIO */
2 编写LED_GPIO初始化函数
※别忘了使能时钟
void LED_GPIO_Config(void){
GPIO_InitTypeDef GPIO_InitStructure;
//开启时钟
RCC_APB2PeriphClockCmd(LED_G_GPIO_CLK, ENABLE);
//配置绿灯
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LED_G_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_G_GPIO_PORT, &GPIO_InitStructure);
}
3 编写main函数
{
LED_GPIO_Config();
GPIO_ResetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
while(1);
}