The NEW Elapsed Timer does, ... well .. it does exactly the same thing as the old Elapsed Timer. But now it works with the Instant Interrupt system. Which means that you can use many other interrupts in the same program without much trouble at all. Unlike the last version.
Here's an example of just the Elapsed Timer by itself.
Code:
INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_INT.bas" ; Elapsed Timer Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM
GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer
Main:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
GOTO Main
Code Size = 537 Words
This will create a Clock counting at 1/100 seconds. It runs in the background of PBP without any other program intervention required.
The time is kept in the variables:
Code:
Ticks var byte ' 1/100th of a second
Seconds var byte ' 0-59
Minutes var byte ' 0-59
Hours var byte ' 0-23
Days var word ' 0-65535
The time can be easily displayed with a single line:
Code:
LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
For each of the variables (Seconds, Minutes, Hours and Days) there is a flag
that indicates when the value of that variable has changed. The Flags are:
SecondsChanged var bit
MinutesChanged var bit
HoursChanged var bit
DaysChanged var bit
If you wanted to display the time like a clock, you could wait until
SecondsChanged = 1, display the time, then reset the flag.
Code:
Loop1:
if SecondsChanged = 1 then
LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
SecondsChanged = 0
endif
Goto Loop1
If you only wanted to display the time each minute instead of every second
just do the same thing using the MinutesChanged flag.
Code:
Loop1:
if MinutesChanged = 1 then
LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes
MinutesChanged = 0
endif
Goto Loop1
The timer can be Stopped and Started, like a stopwatch.
Code:
Gosub StopTimer
Gosub StartTimer
Bookmarks