先看实验现象
参照泽哥的代码,将GPIO_0实现的呼吸灯移植到LED模块(当然也试过GPIO_0处的,明明代码基本都是全部抄过去的,但就是不亮,后来才发现没有共地)
- #include "bflb_mtimer.h"
- #include "bflb_pwm_v2.h"
- #include "bflb_clock.h"
- #include "bflb_gpio.h"
- #include "board.h"
- struct bflb_device_s *pwm;
- struct bflb_device_s *gpio;
- int main(void)
- {
- board_init();
-
- gpio = bflb_device_get_by_name("gpio");
- pwm = bflb_device_get_by_name("pwm_v2_0");
- bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_3);
- bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_3);
- bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_3);
-
- struct bflb_pwm_v2_config_s cfg = {
- .clk_source = BFLB_SYSTEM_XCLK,
- .clk_div = 40,
- .period = 1000,
- };
- bflb_pwm_v2_init(pwm, &cfg);
- bflb_pwm_v2_start(pwm);
- uint8_t i;
- while(1)
- {
- bflb_pwm_v2_channel_positive_start(pwm, PWM_CH0); //12管脚对应着CH0通道()
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, i, 100);
- arch_delay_ms(20);
- }
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, 100 - i, 100);
- arch_delay_ms(20);
- }
- bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH0);
- bflb_pwm_v2_channel_positive_start(pwm, PWM_CH2); //14管脚对应着CH2管道
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH2, i, 100);
- arch_delay_ms(20);
- }
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH2, 100 - i, 100);
- arch_delay_ms(20);
- }
- bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH2);
- bflb_pwm_v2_channel_positive_start(pwm, PWM_CH3); //15管脚对应着CH3管道
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH3, i, 100);
- arch_delay_ms(20);
- }
- for(i=1;i<100;i++)
- {
- bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH3, 100 - i, 100);
- arch_delay_ms(20);
- }
- bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH3);
- }
- }
复制代码 以上就是本节所有内容,附加一份数据手册
BL616_BL618_数据手册.pdf
(1.17 MB, 下载次数: 4)
|