CV大法直接贴源码
#include "wm_include.h"
#include "wm_gpio_afsel.h"
//#include "wm_cpu.h"
// extern int pwm_demo(u8 channel, u16 freq, u8 duty, u8 mode, u8 num);
volatile int pwmend = 0;
u8 duty = 255, a = 1;
void pwmcb()
{
pwmend = 1;
}
void UserMain(void)
{
printf("\n user task \n");
u8 channel = 3;
u8 freq = 100;
u8 pnum = 1;
//pwm_demo(channel,freq,dute,4,pnum);
//<<为使用w801开发板上的led,请参考pwm_demo
wm_pwm3_config(WM_IO_PB_25);//使用pwm3
tls_pwm_stop(channel);
int ret = tls_pwm_init(channel, freq, duty, pnum);//设置pwm
if(ret != WM_SUCCESS)
{
printf("pwm err");
return;
}
//>>为使用w801开发板上的led
tls_pwm_stoptime_irq_cmd(channel, true);//pwm停中断
tls_pwm_isr_register(pwmcb);//注册中断
tls_pwm_start(channel);//pwm开始
while(1) {
if(pwmend == 1) {
tls_reg_write32(HR_PWM_INTSTS,BIT(channel));//清中断
if(duty == 255)
{
a = -1;
printf("-");
}
if(duty == 1)
{
a = 1;
printf("+");
}
duty += a;
//printf("%d ",duty);
pwmend = 0;
//tls_os_time_delay(500);
tls_pwm_duty_set(channel, duty);//调占空比
}
}
#if DEMO_CONSOLE
// CreateDemoTask();
#endif
//用户自己的task
}