点击查看代码
/**
******************************************************************************
* @file main.c
* @author
* @version
* @date 2024/06/27
* @brief 实现利用MCU的PF9引脚控制开发板的4盏LED灯的亮灭
LED0 -- PF9
LED1 -- PF10
LED2 -- PE13
LED3 -- PE14
******************************************************************************
**/
#include "stm32f4xx.h" //必须包含
int main()
{
//1.定义GPIO外设的结构体变量
GPIO_InitTypeDef GPIO_InitStructure;
//2.打开GPIOF端口、GPIOE端口的时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF, ENABLE);
//3.配置PF9引脚为输出模式
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_NOPULL;
//4.对GPIOF端口进行初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;
GPIO_Init(GPIOE, &GPIO_InitStructure);
while(1)
{
//5.控制PF9引脚输出低电平,则LED会亮
GPIOF->BSRRH = GPIO_Pin_9;
GPIOF->BSRRH = GPIO_Pin_10;
GPIOE->BSRRH = GPIO_Pin_13;
GPIOE->BSRRH = GPIO_Pin_14;
}
}