3.6定时器实验

本例使用W800芯片内置的硬件定时器定时2S,每隔2S控制LED闪烁。在UserMain中配置定时器时间2S,同时注册定时器回调函数demo_timer_irq。初始化IO口用于控制LED。

void UserMain(void)
{
printf("\n user task \n");
u8 timer_id;
struct tls_timer_cfg timer_cfg;

	timer_cfg.unit = TLS_TIMER_UNIT_MS;
	timer_cfg.timeout = 1000;
	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\n");
	tls_gpio_cfg(WM_IO_PB_07, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);//配置为上拉输出

}
在定时器中断函数中执行LED状态取反。实现LED闪烁效果。
int bit_io=0;
static void demo_timer_irq(u8 *arg)
{

bit_io=!bit_io;
printf("timer irq\n");
tls_gpio_write(WM_IO_PB_07,bit_io);

}

posted @ 2020-12-09 15:37  深圳四博智联科技有限公司  阅读(212)  评论(0编辑  收藏  举报