本例使用W800芯片内置的硬件定时器定时2S,每隔2S控制LED闪烁。在UserMain中配置定时器时间2S,
同时注册定时器回调函数demo_timer_irq。初始化PB0的引脚用于控制LED。
void UserMain(void)
{
printf("
user task
");
u8 timer_id;
struct tls_timer_cfg timer_cfg;
timer_cfg.unit = TLS_TIMER_UNIT_MS;
timer_cfg.timeout = 2000;
timer_cfg.is_repeat = 1;
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
");
tls_gpio_cfg(WM_IO_PB_00, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);//PB0配置为上拉输出
}
在定时器中断函数中执行LED状态取反。实现LED闪烁效果。
int bit_io=0;
static void demo_timer_irq(u8 *arg)
{
bit_io=!bit_io;
printf("timer irq
");
tls_gpio_write(WM_IO_PB_00,bit_io);
}