Comments (3)
from multitimer.
我一般这样用
#ifndef TIMER_H
#define TIMER_H
#include "NewType.h"
#define tType uint16
enum TimerOut { TIMERRST = 0, TIMEROUT = 1 };
typedef struct TIMER {
uint8 TimeOut;
tType Value;
} Timer, *pTimer;
extern void TimerStart(pTimer t, tType time);
extern void TimerStop(pTimer t);
extern void TimerRun(pTimer t);
extern uint8 TimerOut(pTimer t);
#endif
#include "Timer.h"
//启动已经停止的定时器,如果定时器已经启动或时间到则忽略.
void TimerStart(pTimer t, tType time) {
if ((t->Value == 0) && (t->TimeOut == TIMERRST)) {
t->Value = time;
}
}
//重新设置定时时间并启动定时器,不管时间是否到或定时器是否启动
void TimerSet(pTimer t, tType time) {
t->Value = time;
t->TimeOut = TIMERRST;
}
//停止定时器,清除时间到标志
void TimerStop(pTimer t) {
t->Value = 0;
t->TimeOut = TIMERRST;
}
//在1ms定时器内递减,时间到时设置标志为1
void TimerRun(pTimer t) {
if (t->Value > 0) {
t->Value--;
if (t->Value == 0) {
t->TimeOut = TIMEROUT;
}
}
}
//定时器时间到,并清除时间到标志为0
uint8 TimerOut(pTimer t) {
uint8 result = t->TimeOut;
if (t->TimeOut == TIMEROUT) {
t->TimeOut = TIMERRST;
}
return result;
}
//使用
void Tick1ms(void){
TimerRun(&tm1);
TimerRun(&tm2);
TimerRun(&tm3);
}
while(1){
if ( setp == 1){
if (...){
TimerStart(&tm1, 1000);
} else {
TimerStop(&tm1);
}
}
......
if (TimerOut(&tm1)) {
......
TimerStart(&tm2, 1000);
}
if (TimerOut(&tm2)) {
......
TimerStart(&tm3, 1000);
}
}
from multitimer.
Related Issues (12)
- 超时溢出有问题 HOT 18
- 提点需求,希望能完善该项目 HOT 1
- platformTicksFunction 指针未做判空处理 HOT 1
- PlatformTicksGetFunc() 系统时间溢出怎么处理 HOT 3
- timer_tick是否考虑添加形参,由外部指定tick 频率
- 如何解决带参函数的定时 HOT 2
- 会消耗100%的cpu
- MultiTimer
- main.c没上传吗? HOT 1
- BUG HOT 2
- 不用的定时器资源无法回收 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multitimer.