msTimerWORD  and  SecTimerWORD

Purpose: Determine if a desired medium time period has passed.
Assumes: System interrupts are enabled, so the Operating System is able to update ulT0_Millis and ulT0_Seconds.
Passed:    R25:R24  WORD   wStart the millisLowWORD() value saved at the starting time, OR
the SystemSecondsLowWORD() value saved at the starting time
R23:R22  WORD wDuration   the timer delay time, 0 to 65,530 milliseconds (for msTimerWORD), OR
the timer delay time, 0 to 65,530 Seconds (for SecTimerWORD)
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 flagset (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: R0, R22 through R27, and the FLAGS
Example:  This example assumes "normal" Register usage rules: able to change R0, R18 through R27 and R31:R30 without saving and restoring them.
AToggle_DO_2 = 0x3008             ; FLASH address of the Toggle_DO_2 subroutine
wMyTimer = 0x700                  ; SRAM address of 2 WORD variables
WDEFAULT = 500                    ; Default delay duration of 500 mSec

BlinkTimer:
   LDI     R31, wMyTimer >> 8     ; Point 'Z' at the 2 WORD variables above
   LDI     R30, wMyTimer & 0xFF
   LD      R24, Z                 ; Read the first WORD, the duration (the low
   LDD     R25, Z + 1             ;  order BYTE is read first, into R24)
   ADIW    R24, 0                 ; See if the duration has been initialized
   BRNE    ASetDuration           ; If so, don't reinitialize it
   LDI     R25, WDEFAULT >> 8
   LDI     R24, WDEFAULT & 0xFF
   ST      Z    , R24             ; Load and store the default delay duration
   STD     Z + 1, R25             ;  which also sets it in R25:R24

SetDuration:
   MOVW    R22, R24               ; Move the duration mSec value to R23:R22
   LDD     R24, Z + 2
   LDD     R25, Z + 3             ; Read the last saved starting time - if it
   CALL    AmsTimerWORD           ;  is zero, it may time out immediately
   BREQ    ATimerDone
   CALL    AmillisLowWORD         ; Read milliseconds LSWord into R25:R24
   STD     Z + 2, R24             ; Reset the timer - update the starting time
   STD     Z + 3, R25             ;  with the present system mSec time WORD
   CALL    AToggle_DO_2           ; Call to do the work: flip the LED state

TimerDone:
   RET
The "@" command could be used to initially test the example routine above.
Notes: See the notes in the msTimerBYTE and SecTimerBYTE functions.
Dropin: 
(setup
code)
;   Setup for the msTimerWORD() or SecTimerWORD() call:
; Passed:  R25:R24 WORD  the millisLowBYTE() value saved at the starting time
;                        or the SystemSecondsLowBYTE saved at starting time
;          R23:R22 WORD  the duration of the delay (0 to 65,530, milliseconds)
;                        or the delay duration in seconds (0 to 65,530 seconds)
;                        Note: values from 65,531 to 65,535 may be passed, will be
;                             limited to 65,530, 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:  R0, R22 through R27 and FLAGS (R24 has the return value)
Also see:  The millis and SystemSeconds variables, the msTimerBYTE, SecTimerBYTE, and msTimerULONG timers.