bsp_led.h
#ifndef __BSP_LED_H__
#define __BSP_LED_H__
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
// 红灯
#define LED_R_PIN GPIO_Pin_10
#define LED_R_PORT GPIOH
#define LED_R_CLK RCC_AHB1Periph_GPIOH //此处最开始直接复制了标准库对于H端口的时钟使能宏,但是标准库中H端口错写成G口,导致LED不点亮
// 绿灯
#define LED_G_PIN GPIO_Pin_11
#define LED_G_PORT GPIOH
#define LED_G_CLK RCC_AHB1Periph_GPIOH //此处最开始直接复制了标准库对于H端口的时钟使能宏,但是标准库中H端口错写成G口,导致LED不点亮
// 蓝灯
#define LED_B_PIN GPIO_Pin_12
#define LED_B_PORT GPIOH
#define LED_B_CLK RCC_AHB1Periph_GPIOH //此处最开始直接复制了标准库对于H端口的时钟使能宏,但是标准库中H端口错写成G口,导致LED不点亮
//操作寄存器方法控制LED输出
#define OutH(Port,Pin) {Port->BSRRL = Pin;} //输出高电平
#define OutL(Port,Pin) {Port->BSRRH = Pin;} //输出低电平
#define Toggle(Port,Pin) {Port->ODR ^= Pin;} //反转
//定义LED宏
#define LED_R_ON OutL(LED_R_PORT,LED_R_PIN)
#define LED_R_OFF OutH(LED_R_PORT,LED_R_PIN)
#define LED_R_TOGGLE Toggle(LED_R_PORT,LED_R_PIN)
#define LED_G_ON OutL(LED_G_PORT,LED_G_PIN)
#define LED_G_OFF OutH(LED_G_PORT,LED_G_PIN)
#define LED_G_TOGGLE Toggle(LED_G_PORT,LED_G_PIN)
#define LED_B_ON OutL(LED_B_PORT,LED_B_PIN)
#define LED_B_OFF OutH(LED_B_PORT,LED_B_PIN)
#define LED_B_TOGGLE Toggle(LED_B_PORT,LED_B_PIN)
//基本色
#define LED_RED LED_R_ON;LED_G_OFF;LED_B_OFF //红灯亮
#define LED_GREEN LED_R_OFF;LED_G_ON;LED_B_OFF //绿灯亮
#define LED_BLUE LED_R_OFF;LED_G_OFF;LED_B_ON //蓝灯亮
#define LED_OFF LED_R_OFF;LED_G_OFF;LED_B_OFF //所有灯灭
void Led_Config(void);
#endif /* __BSP_LED_H__ */
|
———————————————— 版权声明:本文为CSDN博主「放学校门口见」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/guanxiaozhi/article/details/130726092