1. RGB彩灯混色
RGB彩灯实际上由三盏分别为红、绿、蓝的LED灯组成的,通过控制RGB颜色强度的组合,可以混合出各种彩色。
/* 基本混色*/
// LED1(R)/ LED2(G)/ LED3(B)
//红
#define LED_RED
LED1_ON;
LED2_OFF;
LED3_OFF
//绿
#define LED_GREEN
LED1_OFF;
LED2_ON;
LED3_OFF
//蓝
#define LED_BLUE
LED1_OFF;
LED2_OFF;
LED3_ON
//黄(红+绿)
#define LED_YELLOW
LED1_ON;
LED2_ON;
LED3_OFF
//紫(红+蓝)
#define LED_PURPLE
LED1_ON;
LED2_OFF;
LED3_ON
//青(绿+蓝)
#define LED_CYAN
LED1_OFF;
LED2_ON;
LED3_ON
//白(红+绿+蓝)
#define LED_WHITE
LED1_ON;
LED2_ON;
LED3_ON
//黑(全部关闭)
#define LED_RGBOFF
LED1_OFF;
LED2_OFF;
LED3_OFF
2. 控制流程
初始化系统时钟
初始化相应GPIO时钟
配置GPIO
根据需要亮灯
3. 断言
stm32f4xx_conf.h文件中关于断言的定义
/* Uncomment the line below to expanse the "assert_param" macro in the
Standard Peripheral Library drivers code */
/* #define USE_FULL_ASSERT 1 */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
库文件只对“assert_failed”写了函数声明,没有写函数定义,实际用时需要用户来定义,我们一般会用printf函数来输出这些信息。(注:前提需要支持printf)
4. Doxygen注释
“Doxygen”的注释规范,如果在工程文件中按照这种规范去注释,可以使用Doxygen软件自动根据注释生成帮助文档。
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』