Soft Real Time Clock

#1
I needed an RTC for a project using the IRIN instruction, which is blocking and stops everything else including the time function.

The result was that the "time" runs at about 1/3rd real time. To work around it I used a multiplier in the 1st line. Good enough for my needs - and free !

;SoftRTC
Secs = time * 3 ; the *3 compensates for the IRIN blocking impact - change to suit y
If Secs => 60 then
time = 0
Mins = Mins + 1
endif
if Mins => 60 then
Hours = Hours + 1
Mins = 0
endif
;If Hours = 24 then ; I didn't need a 24 hour clock so just let the hours count up to 99 and roll over
; Hours = 0
;endif
;EndSoftRTC

And to display the time :-

TD: ; If clock chip available get time and display it at (pre-set) cursor position
; Use of SoftRTC Time subroutine - Hours, Mins, Secs
; Put cursor at start of time position separately

bintoascii Hours,Hundreds,Tens,Units
gosub TimeDisplay
DataIn = ":"
gosub ASCII_display
bintoascii Mins,Hundreds,Tens,Units
gosub TimeDisplay
DataIn = ":"
gosub ASCII_display
bintoascii Secs,Hundreds,Tens,Units
gosub TimeDisplay
;
goto IR ; processed so go for next character from IRIN or serial if you prefer
TimeDisplay:
DataIn = Tens
gosub ASCII_display
DataIn = Units
gosub ASCII_display
return
 
Top