Elapsed time display (X1)


Senior Member
One of my projects requires a simple time display, so I've been experimenting with an X1 chip and the settimer function. I noticed there is no code for this on the forum yet, so here is a starter using an LCD to display elapsed time in the format mm:ss (maximum of 99:59).

It would be a simple matter to use the code to show elapsed hours as well by using the same logic applied to the minutes display.

Thanks to previous posters who have helped explain the workings of settimer.

; Elapsed timer code snippet
; for use on picaxe 28X1 and 40X1
 symbol bMins=b0  'count of minutes (calculated from wTicks)
 symbol bSecs=b1  'count of seconds (remainder ie. wTicks - bMins)
 symbol wTicks=w1  'wTicks is the number of seconds counted
 symbol wMinSecs=w2 'is the total number of seconds represented by minutes (used to calculate the seconds value)
 symbol oLCD=0 'serial output to LCD
 serout oLCD, N2400, (254,1) 'clear display
 serout oLCD, N2400, ("LCD timer", 254,192)
 serout oLCD, N2400, ("using X1s")
 pause 1000
 'sets up the initial info on the timer screen
 serout oLCD, N2400, (254,1) 'clear display
 serout oLCD, N2400, ("Time 00:00", 254,192)
 serout oLCD, N2400, ("     mm:ss")
 settimer t1s_4    'settimer to 1 second ticks at 4MHz
 Timer=$ffff   'set timer to generate interrupt on next timer overflow
 setintflags $80,$80 'enable timer interrupt
 'put in anything you want the code to do here
 'the code will 'interrupt' every second
 goto main
 'interrupt is triggered by toflag
 'toflag triggers when timer excedes $ffff
 'process and update timer display
 'wTicks is used to keep a count of seconds
  'if timer was not being used to trigger an interrupt,
  'the value of timer could be used to record seconds count
 inc wTicks 'add another tick
 if wTicks>5999 then
  'we have reached the max of 99:59 - reset to 00:00
 bMins=wTicks/60 'divide by total seconds by 60 to get minute value
 wMinSecs=bMins*60 'this is the total number of seconds represented by the minutes value
 bSecs=wTicks-wMinSecs 'the remainder of the two gives the seconds count
 'move to position for writing to LCD
 serout oLCD, N2400, (254,133) 'move to start of mins write position
 if bMins<10 then
  'add a leading 0
  serout oLCD, N2400, ("0")
 serout oLCD, N2400, (#bMins, ":") 'write the minutes value to LCD
 if bSecs<10 then
  'add a leading 0
  serout oLCD, N2400, ("0")
 serout oLCD, N2400, (#bSecs) 'write the seconds value to LCD
 toflag = 0   'clear the timer overflow flag
 timer = $ffff  'initialise timer to interupt on next count
 setintflags $80,$80 'enable the timer interrupt
 return    ‘return


Senior Member

Your project dovetails with something that popped into my mind yesterday morning.

Engines for which running time is important usually have a Hobbs meter mounted on their control panels. (Examples include stationary generators, light aircraft engines, etc.) The Hobbs meter accumulates running time which determines when the engine needs to be overhauled. (For aircraft in rental service, Hobbs meter time is also used to determine the billing.)

It should be simple to build an electronic equivalent using a Picaxe. The processor would have some sort of signal, perhaps derived from the engine's ignition system, that would indicate the engine is powered and running. The Picaxe would accumulate the running time to its EEPROM and either display said time on a display or have the time available for remote readout.

I don't know if there's a demand for something like this, but if you need one, it might be a cool little project.

Have fun!



New Member
Hobbs meter

That is exactly what I'm looking here for. Except I want an enhanced version. I have a small 750VA genset and I figured that if I type in the fuel I put in the tank it could record that as well. Then if I get carried away I could mesure the output and display $ per kwH but that is a figure I dont want to know ! I was thinking of simply using the 12v to run the meter and tell if it was running or not. I would need nonvolatile RAM. What have you done for a display ?



Oil pressure switch is what most meters use to signal activity. Probably free at the junkyard. Most cars have them for the idiot light.
If the gen set already has a low oil cutoff you are all set.


New Member
Nice code, I had a play and added hours and days, with the limit at 98 days, 23 hours, 59 mins, 59 secs, after which it pauses....havnt waited in excess of 98 days to check it though...