【发布时间】:2020-02-08 09:12:14
【问题描述】:
我有以下 C 代码:
int count = 0; // relative time
int T1 = 20; // period 1 in ms
int T2 = 50; // period 2 in ms
int T3 = 80; // period 3 in ms
while (1) {
if (count%T1 == 0) function1();
if (count%T2 == 0) function2();
if (count%T3 == 0) function3();
count++;
if (count == T1*T2*T3) count = 0;
delay(1); // wait for 1 ms
}
我想知道整数除法 count%T1==0 而不是 count==T1 的原因。也许是考虑到周期T1可能不是整数?
提前谢谢你。
【问题讨论】:
标签: c integer-division