w801開發板呼吸燈

發布於 2023-05-15 10:45:43

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
}
0 條評論

發布
問題