硬件分析
    image.png
    PF9 PF10 低电平 LED 亮

    初始化GOIOF的 9 和 10

    1. void LEDInit(void)
    2. {
    3. 创建 GPIO_InitTypeDef 类型的 结构体
    4. 打开系统时钟 void RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
    5. LED_gpio.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10 ; //
    6. LED_gpio.GPIO_Mode = GPIO_Mode_OUT; //输出模式
    7. LED_gpio.GPIO_Speed = GPIO_Medium_Speed; //中速
    8. LED_gpio.GPIO_OType = GPIO_OType_PP; //推挽模式
    9. LED_gpio.GPIO_PuPd = GPIO_PuPd_UP; //上拉 保持不给低电平不亮的状态
    10. }

    GPIO_SetBits(GPIOx,GPIO_Pin_x) 设置高电平 关灯
    GPIO_ResetBits(GPIOx,GPIO_Pin_x) 设置低电平 开灯

    led.h
    #include “stm32f4xx.h”
    #include “stm32f4xx_gpio.h”
    #include “delay.h”

    1. /*main.c */
    2. #include "led.h"
    3. delay_init(168);
    4. LED_Init();
    5. while(1) // 无限循环
    6. {
    7. LED1_On();
    8. delay_ms(100);
    9. LED1_Off();
    10. delay_ms(100);
    11. LED2_On();
    12. delay_ms(100);
    13. LED2_Off();
    14. delay_ms(100);

    a.gif