AXE133Y Evolution with 20X2 for Display, 12- hour Clock, & Temperature

mrburnette

Senior Member
Continued on: AXE13Y Clock Battery Backup

Continued from: http://www.picaxeforum.co.uk/entry.php?46-Hack-OLED-AXE133Y-to-upgrade-18M2-to-a-20X2-PICAXE

The port of the 18M2 to the 20X2 was very simple and building a daughter-board for the AXE133Y was very simple, too. In this installment, I enhance the code to support the AM/PM indicator and to display in non-military time... this model is going on my wife's night stand and she asked for the change... a matter of preference. So, I decided to post the entire code in case anyone wanted to cannibalize some of the routines.

The 20X2 codebase (OLED support + time 'n display + temperature) is now at 38% with plenty of room left for additional code... and I have at least 500mS of free time to play around with at present before the time-critical loop must recycle.

Old Concept:
Previously, I had the following crude code running in a loop which executed every second:
Code:
	secs = secs + 1 // 60
	If secs = 0 Then
		mins = mins + 1 // 60
      	        If mins = 0 Then
      		     hour = hour + 1 // 24
      	        EndIf
        EndIf
Not all that elegant, but it works. The associated display code for the OLED look like this:
Code:
 	Case 2	; Called every second to update time on OLED bottom line1
 			;_____RAM MAP________
 			;55556666666666777777
 			;67890123456789012345
 			;sfcc....HH:MM:SS....   s=start, f=finish, c/c=control_bytes
 			;
 		POKE 58,254,192
 		Line = 1 : GoSub DisplayRAM
 		POKE 58,0,0
 		
 		If hour = 0 then
 			; EQ = serout Serial,BAUD,("    00:")
 			POKE 64,"0","0",":"
 		elseif hour < 10 then
 			; EQ = serout Serial,BAUD,("    0",#hour,":")
 			tempL = hour + 48
 			POKE 64,"0",tempL,":"
 		else
 			; EQ = serout Serial,BAUD,("    ",#hour,":")
 			tempL = hour //10 + 48
 			tempH = hour / 10 + 48
 			POKE 64,tempH,tempL,":"
 		endIf
 		
 		If mins = 0 then
 			POKE 67, "0","0",":"
 		elseif mins < 10 then
 			tempL = mins + 48
 			POKE 67, "0",tempL,":"
 		else
 			tempL = mins //10 + 48
 			tempH = mins / 10 + 48
 			POKE 67,tempH,tempL,":"
 		endIf
 		
 		If secs = 0 then
 			POKE 70,"0","0"
 		elseif secs < 10 then
 			tempL = secs + 48
 			POKE 70,"0",tempL
 		else
 			tempL = secs //10 + 48
 			tempH = secs / 10 + 48
 			POKE 70, tempH, tempL
 		endIf
 		
 		GoSub DisplayRAM
View attachment 10379

In contemplating the AM/PM implementation, I had wanted to just carry a sum of seconds for 24 hours:
24hours x 60mins/hour x 60secs/min = 86400... Oops! Too big for 16-bits.
So, I fell back to summing the minutes for 24 hours:
24 x 60 = 1440 minutes which is a nice figure for a PICAXE word value.

The new code looks like this:
Code:
	hours = tMin / 60
	mins = tMin // 60

	IF tMin > 719 then
		AmPm = 1			; afternoon
	Else
		AmPm = 0			; morning
	EndIF
And the associated display routine appears as:
Code:
Disp2:
		; Called every second to update time on OLED bottom line1
 		;_____RAM MAP________
 		;55556666666666777777
 		;67890123456789012345
 		;sfcc.?M.HH:MM:SS....   s=start, f=finish, c/c=control_bytes
 		;
 		POKE 58,254,192
 		Line = 1 : GoSub DisplayRAM
 		POKE 58,0,0,32,80,77	; clear control info and poke " P" in pos 61
 		
 		IF AmPm = 0 then
 			POKE 61, 65		; "A"
 		EndIF
 		
 		tempH = 32			; space
 
 		IF hours > 12 then
 			hours = hours - 12
 		endIF
 		;EQ = serout Serial,BAUD,("    ",#hours,":")
 		IF hours > 9 and hours <=12 then	; display 2 digits: 10, 11, 12
 			tempH = 49				; "1"
 		endIF
 
 		tempL = hours //10 + 48
 		
 		POKE 64,tempH,tempL,":"
 		
 		IF mins = 0 then
 			POKE 67, "0","0",":"
 		elseIF mins < 10 then
 			tempL = mins + 48
 			POKE 67, "0",tempL,":"
 		else
 			tempL = mins //10 + 48
 			tempH = mins / 10 + 48
 			POKE 67,tempH,tempL,":"
 		EndIF
 		
 		IF secs = 0 then
 			POKE 70,"0","0"
 		elseIF secs < 10 then
 			tempL = secs + 48
 			POKE 70,"0",tempL
 		else
 			tempL = secs //10 + 48
 			tempH = secs / 10 + 48
 			POKE 70, tempH, tempL
 		EndIF
 		
 		GoSub DisplayRAM : Return
With Valentine Day coming up, at least her clock will display in the manner she desires... now, just to make those dinner reservations!

- Ray

View attachment 10378

Note: When setting with the "sony-ish" IR remote control, military time format must still be utilized. Somewhere in the future, I'll add a soft-option for 12/24 hour display.
 
Top