联盛德W801流水灯

该代码演示了一个使用WMTimer库实现的LED循环闪烁程序。通过定义GPIO引脚并配置定时器,每隔500ms改变LED的状态,实现了LED的交替亮灭。定时器配置为重复模式,当计数到达预设值时触发中断,切换LED状态。
摘要由CSDN通过智能技术生成
#include "wm_include.h"
#include "wm_timer.h"

unsigned char led[]={WM_IO_PB_05,WM_IO_PB_25,WM_IO_PB_26,WM_IO_PB_18,WM_IO_PB_17,WM_IO_PB_16,WM_IO_PB_11};
int n=0;
bool colse=false;
static void demo_timer_irq(u8 *arg)
{
    tls_gpio_write(led[n], colse); //0亮灯 1灭灯
    n++;
    if(n>6){
        n=0;
        colse=!colse;
    }
}

int timer_demo(void)
{
    u8 timer_id;
    struct tls_timer_cfg timer_cfg;
    timer_cfg.unit = TLS_TIMER_UNIT_MS;
    timer_cfg.timeout = 500;//定时时间单位ms,1000 ->1S
    timer_cfg.is_repeat = true;
    timer_cfg.callback = (tls_timer_irq_callback)demo_timer_irq;
    timer_cfg.arg = NULL;
    timer_id = tls_timer_create(&timer_cfg);
    tls_timer_start(timer_id);
    printf("timer start\n");
    return WM_SUCCESS;
}

void UserMain(void)
{
    printf("\n Hello World! \r\n");
    #if DEMO_CONSOLE
		CreateDemoTask();
    #endif
    //用户自己的task
    for(int i=0;i<7;i++){
        tls_gpio_cfg(led[i], WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);//将GPIO口设置为输出模式,上拉
    }

    timer_demo();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值