freertos 软件定时器

本文介绍了如何在FreeRTOS中创建和使用软件定时器。通过示例代码展示了如何创建两个定时器,设置不同周期,并定义回调函数处理定时器事件。定时器的启动、停止和活动状态检查等功能也得到了演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TimerHandle_t xTTimerHd1;
TimerHandle_t xTTimerHd2;
void vTimerCallback(void)
{
static u32 a = 1;
u32 b = 0;
printf(“fast:%d\r\n”,a++);
//xTimerReset( xTTimerHd2, 0 );
if(a==5)
xTimerStop(xTTimerHd2,0);
b = xTimerIsTimerActive(xTTimerHd2);
printf(“b is:%d\r\n”,b);
b = xTimerIsTimerActive(xTTimerHd1);

}

void vTimerCallback2(void)
{
static u8 a = 1;
printf(“slow:%d\r\n”,a++);
}

xTTimerHd1 = xTimerCreate( /* Just a text name, not used by the RTOS kernel. /
“Timer1”,
/
The timer period in ticks, must be greater than 0. /
1000/portTICK_PERIOD_MS,
/
The timers will auto-reload themselves when they
expire. /
pdTRUE,
/
The ID is used to store a count of the number of
times the timer has expired, which is initialized to 0. /
( void * ) 0,
/
Each timer calls the same callback when it expires. /
vTimerCallback );
xTTimerHd2= xTimerCreate( /
Just a text name, not used by the RTOS kernel. /
“Timer3”,
/
The timer period in ticks, must be greater than 0. /
2000/portTICK_PERIOD_MS,
/
The timers will auto-reload themselves when they
expire. /
pdTRUE,
/
The ID is used to store a count of the number of
times the timer has expired, which is initialized to 0. /
( void * ) 0,
/
Each timer calls the same callback when it expires. */
vTimerCallback2 );

xTimerStart( xTTimerHd1, 0 );
xTimerStart( xTTimerHd2, 0 );
tms = xTimerIsTimerActive(xTTimerHd1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值