Elapsed Timer for 18F's

Here's a version of the Elapsed Timer for 18F's by itself.
Example 2:

; Initialize your Hardware and LCD first

INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Elapsed_INT-18.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
ENDASM

@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

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 = 1188 bytes
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:

    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:

    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.

    Loop:
        if SecondsChanged = 1 then
           LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
           SecondsChanged = 0
        endif
    Goto Loop

If you only wanted to display the time each minute instead of every second just do the same thing using the MinutesChanged flag.

    Loop:
        if MinutesChanged = 1 then
           LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes
           MinutesChanged = 0
        endif
    Goto Loop

The timer can be Stopped and Started, like a stopwatch.

    Gosub StopTimer
    Gosub StartTimer

Download the files here: (Right click and Save As)

Page last modified on March 02, 2018, at 04:28 AM