看硬件,原理图可知,RGB灯分别与PA26 PA13 PA27通过短接帽可以连在一起
再通过说明书可知,三个引脚分别处于TIMG0通道1,TIMG1通道0和1
根据硬件配置
生成程序。添加呼吸灯代码(循环修改占空比),原理就是不停的改变IO口的占空比,使LED在视觉效果上逐渐变化,形成呼吸的效果
int main(void) { unsigned short i; SYSCFG_DL_init(); SIG_R_OFF; DL_TimerG_setCaptureCompareValue(PWM_0_INST, 999, DL_TIMER_CC_1_INDEX); DL_TimerG_setCaptureCompareValue(PWM_1_INST, 999, DL_TIMER_CC_1_INDEX); DL_TimerG_setCaptureCompareValue(PWM_1_INST, 999, DL_TIMER_CC_0_INDEX); while (1) { for (i = 1000; i > 0; i--) { DL_TimerG_setCaptureCompareValue(PWM_1_INST, i, DL_TIMER_CC_0_INDEX); delay_cycles(32000); // 延迟 } for (i = 0; i < 1000; i++) { DL_TimerG_setCaptureCompareValue(PWM_1_INST, i, DL_TIMER_CC_0_INDEX); delay_cycles(32000); // 延迟 } delay_cycles(DELAY); // 延迟 for (i = 1000; i > 0; i--) { DL_TimerG_setCaptureCompareValue(PWM_0_INST, i, DL_TIMER_CC_1_INDEX); delay_cycles(32000); // 延迟 } for (i = 0; i < 1000; i++) { DL_TimerG_setCaptureCompareValue(PWM_0_INST, i, DL_TIMER_CC_1_INDEX); delay_cycles(32000); // 延迟 } delay_cycles(DELAY); // 延迟 for (i = 1000; i > 0; i--) { DL_TimerG_setCaptureCompareValue(PWM_1_INST, i, DL_TIMER_CC_1_INDEX); delay_cycles(32000); // 延迟 } for (i = 0; i < 1000; i++) { DL_TimerG_setCaptureCompareValue(PWM_1_INST, i, DL_TIMER_CC_1_INDEX); delay_cycles(32000); // 延迟 } delay_cycles(DELAY); // 延迟 } }