硬件分析
PF9 PF10 低电平 LED 亮
初始化GOIOF的 9 和 10
void LEDInit(void)
{
创建 GPIO_InitTypeDef 类型的 结构体
打开系统时钟 void RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
LED_gpio.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10 ; //
LED_gpio.GPIO_Mode = GPIO_Mode_OUT; //输出模式
LED_gpio.GPIO_Speed = GPIO_Medium_Speed; //中速
LED_gpio.GPIO_OType = GPIO_OType_PP; //推挽模式
LED_gpio.GPIO_PuPd = GPIO_PuPd_UP; //上拉 保持不给低电平不亮的状态
}
GPIO_SetBits(GPIOx,GPIO_Pin_x) 设置高电平 关灯
GPIO_ResetBits(GPIOx,GPIO_Pin_x) 设置低电平 开灯
led.h
#include “stm32f4xx.h”
#include “stm32f4xx_gpio.h”
#include “delay.h”
/*main.c */
#include "led.h"
delay_init(168);
LED_Init();
while(1) // 无限循环
{
LED1_On();
delay_ms(100);
LED1_Off();
delay_ms(100);
LED2_On();
delay_ms(100);
LED2_Off();
delay_ms(100);