一个包含各种驱动的工程,main函数中用驱动函数实现功能
C:\Users\LiTao\Desktop\儿童智能硬件资料\my_workspace\pwm
改造实现了PWM两路输出
1 #include <stdbool.h> 2 #include <stdint.h> 3 #include "nrf_delay.h" 4 #include "nrf_gpio.h" 5 #include "boards.h" 6 #include "nrf_pwm.h" 7 8 /** 9 * @brief Function for application main entry. 10 */ 11 int main(void) 12 { 13 uint8_t t; 14 15 nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG;// 16 17 pwm_config.mode = PWM_MODE_LED_255; // 8-bit resolution, 122Hz PWM frequency, 32kHz timer frequency (prescaler 9) 18 pwm_config.num_channels = 2; 19 pwm_config.gpio_num[0] = LED_0; //该设置为使用哪个IO口作为PWM输出 20 pwm_config.gpio_num[1] = LED_1; //该设置为使用哪个IO口作为PWM输出 21 22 nrf_pwm_init(&pwm_config); //pwm初始化 23 24 // Configure LED-pins as outputs 25 nrf_gpio_cfg_output(LED_0); 26 nrf_gpio_cfg_output(LED_1); 27 28 29 30 // LED 0 and LED 1 blink alternately. 31 t=1; 32 while(true) 33 { 34 t=t+1; 35 nrf_pwm_set_value(0, t); 36 nrf_delay_ms(50); 37 38 39 if(t>200)t=0; 40 // nrf_pwm_set_value(1, 200); 41 } 42 }
nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG;[M1]
[M1] PWM结构体
pwm_config.mode = PWM_MODE_LED_255; // 8-bit resolution, 122Hz PWM frequency, 32kHz timer [M1] frequency (prescaler 9)
[M1] 设置PWM模式
pwm_config.num_channels = 2;
pwm_config.gpio_num[0] = LED_0; //该设置为使用哪个IO口作为PWM输出
pwm_config.gpio_num[1] = LED_1; //该设置为使用哪个IO口作为PWM输出[M1]
[M1] PWM两个通道
nrf_pwm_init(&pwm_config); //pwm初始化[M1]
[M1] 初始化PWM
nrf_pwm_set_value(0, t); [M1]
[M1] 设置通道0的占空比为t,满为255,见上面的mode
链接:http://pan.baidu.com/s/1i3vT7cp
时间: 2024-10-21 21:14:45