我一直在苦苦思索如何将一个计时器添加到一个循环中,它会在离散的时间(比如10秒)之后退出。
我要做的是收集RS232接口的输入来填充一个字符串(包括结尾的校验和)。
当接收到校验和时,循环退出。我还想退出,如果我没有收到它在离散的时间量(10秒以上的价值)。
我试图用一个8位计数器来实现它,它被1秒的时钟计时,结果是计数器值为10,退出,但永远不能将计数器重置为下一次的0(保持每10秒退出一次)。
做这类事情的人是如何实现一个时间的,这样你就不会永远在串行处理循环中停留在字符串缓冲区中的垃圾中了吗?
以上来自于百度翻译
以下为原文
I've been struggleing with how to add a
timer to a loop that will exit after a discrete amount of time (say 10 seconds).
What I have going on is I'm collecting input from an RS232 interface to fill up a string (that includes a checksum at the end).
The loop exits when the checksum is received. I also want to exit if I don't receive it after a discrete amount of time (that 10 second value above).
I tried to implement it using a 8 bit counter that was clocked by a 1 seconds clock with the result that I could get the counter value to 10, exit, but never able to reset the counter back to 0 for the next pass (kept exiting every 10 seconds
How do folks that do this type of thing implement implement a time so your not stuck forever in the serial processing loop forever with garbage in the string buffer?
0