Purpose: | Determine if a desired short time period has passed. | |||
Assumes: | System interrupts are enabled, so the Operating System is able to update ulT0_Millis and ulT0_Seconds. | |||
Passed: | R24 | BYTE | bStart | the millisLowBYTE() value saved at the starting time, OR the SystemSecondsLowBYTE() value saved at the starting time |
R22 | BYTE | bDuration | the timer delay time, 0 to 250 milliseconds (for msTimerBYTE), OR the timer delay time, 0 to 250 Seconds (for SecTimerBYTE) |
|
Returns: | R24 | BYTE | bIfDone | 0 (or FALSE) if the specified amount of time has NOT passed OR 1 (or TRUE) if the specified amount of time has passed |
FLAGS | ZERO | flag | set (TRUE) when the time has NOT expired (i.e., when R24 is 0) OR clear (FALSE) when the timer has timed out (i.e., when R24 is 1) |
|
Alters: | R22, R23, R24, and the FLAGS |
Example: | This is more an example of what NOT to do in a multitasking environment, since this code "blocks" and becomes, in effect, a delay function. That is one reason why the millisecond version was chosen for this example. It can be invoked from the command line and is printing a character while waiting, however. Examine Timers for non-blocking, but more intricate, example code. |
| |
Notes: | A delay() function would defeat the purpose of a cooperative multitasking Operating System. Still, there must be some way to selectively defer program execution until a later time; enter timers. A time delay of zero is considered to ALWAYS be timed out. This means that a routine can change a timer delay to zero and have it "fire" (or time out) the next time it's checked. |
Dropin: (setup code) |
; Setup for the msTimerBYTE() or SecTimerBYTE() call: ; Passed: R24 BYTE the initial millisLowBYTE() or SystemSecondsLowBYTE value ; R22 BYTE the delay duration (0 to 250, milliseconds or Seconds) ; Note: values from 251 to 255 may be passed, will be ; limited to 250, and will not cause an error. ; Returns: R24 BYTE 0 if the time delay is not done yet OR ; 1 if (at least) the desired amount of time has passed ; (Also): ZERO FLAG TRUE when the time has NOT passed yet OR ; FALSE when the time has passed ; Alters: R22, R23 and FLAGS (in addition to the return value in R24) |
Also see: | The millis and SystemSeconds variables, the msTimerWORD, SecTimerWORD, and msTimerULONG timers. |