#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();
}
联盛德W801流水灯
最新推荐文章于 2023-06-17 17:59:44 发布
该代码演示了一个使用WMTimer库实现的LED循环闪烁程序。通过定义GPIO引脚并配置定时器,每隔500ms改变LED的状态,实现了LED的交替亮灭。定时器配置为重复模式,当计数到达预设值时触发中断,切换LED状态。
571

被折叠的 条评论
为什么被折叠?



