-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
56 lines (46 loc) · 1.02 KB
/
test.c
File metadata and controls
56 lines (46 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @file test.c
* @author your name (you@domain.com)
* @brief 创建一个定时器,每秒运行一次print_hello函数,运行5次停止
* @version 0.1
* @date 2020-12-24
*
* @copyright Copyright (c) 2020
*
*/
#include "timer.h"
#include <windows.h>
#include <stdio.h>
sl_uint8_t timer_id;
sl_uint8_t run_flag = 1;
void print_hello(void)
{
static sl_uint8_t cnt = 0;
if( ++cnt == 5)
{
cnt = 0;
timer_stop(timer_id);
run_flag = 0;
}
printf("hello, world!\r\n");
}
int main(void)
{
unsigned int tick = 0;
/** 1. 创建定时器 **/
timer_create(&timer_id, TIMER_MODE_CYCLE, print_hello);
/** 2. 启动定时器 */
timer_start(timer_id, 2000);
while (run_flag)
{
if (++tick >= 80000)
{
tick = 0;
/** 3.在tick中断中定时刷新 此处模拟系统滴答时钟中断*/
timer_tick();
}
/** 4. 主循环中定时器消息循环 */
timer_task_loop();
}
return 0;
}