DS1302 and setting/viewing data - HEX2/DEC2
xanatos
Posts: 1,120
If I set the DS1302 with variables in DEC format, and then view the output in DEC, I get ODD counts - the seconds count to 9, then jump 7 (oddly enough...) to 16, where it continues counting...· So I viewed the seconds as HEX2 and they count fine, recycling at 59 as normal.
The issue comes in with the minutes and hours.· If I set in hex, they display ODD numbers.· If I set in DEC, and display in DEC2, I get the same hex count, but if I view in HEX2, I get hex digits in the time (like 0B, 0C, etc).· So...· I am confused, a state I am not unfamiliar with.
I have attached the code I am using below.· I'm sure it's something VERY obvious to most, but it is eluding me at the moment.· The regular demo code for the DS1302 works fine, and what I've done is alter the code to do away with the debug menu input and replace it with simply (for now) a set of hard coded variables (I will be setting the clock remotely to ensure the remote system and the local system's clocks match).· But there seems to be something in the function of receiving the set data in debug mode as Hex.· I've tried setting the data as hev (mins = $0A, for example), but that isn't working.
Please see the code section labeled '
[noparse][[/noparse] VARIABLES THAT WILL BE SET FROM READING CLOCK ON WEB TERMINAL ]---·
In short, I am looking to get proper time display that doesn't have oddities like 12:85:34, or 0C:B3:28.....
Ideas?· Direction?
THANK YOU!!!
Dave
The issue comes in with the minutes and hours.· If I set in hex, they display ODD numbers.· If I set in DEC, and display in DEC2, I get the same hex count, but if I view in HEX2, I get hex digits in the time (like 0B, 0C, etc).· So...· I am confused, a state I am not unfamiliar with.
I have attached the code I am using below.· I'm sure it's something VERY obvious to most, but it is eluding me at the moment.· The regular demo code for the DS1302 works fine, and what I've done is alter the code to do away with the debug menu input and replace it with simply (for now) a set of hard coded variables (I will be setting the clock remotely to ensure the remote system and the local system's clocks match).· But there seems to be something in the function of receiving the set data in debug mode as Hex.· I've tried setting the data as hev (mins = $0A, for example), but that isn't working.
Please see the code section labeled '
[noparse][[/noparse] VARIABLES THAT WILL BE SET FROM READING CLOCK ON WEB TERMINAL ]---·
In short, I am looking to get proper time display that doesn't have oddities like 12:85:34, or 0C:B3:28.....
Ideas?· Direction?
THANK YOU!!!
Dave
Comments
containing seconds, minutes, etc are coded in BCD. That's why you are
getting bad displays when you use DEC2 for the Debug statements.
They only display properly if you use HEX2.
For hours you have to mask off the AM-PM bit.
At the bottom of your Show_Time subroutine, change it to read:
Post Edited (phil kenny) : 6/16/2009 6:00:56 AM GMT
Thanks very much for your input on this (no pun intended!)
Dave
If anyone wants to run the code I am messing with, I have attached it below ("SerialLCD+Clock.bs2") along with the original demo code for the DS1302 ("DS1302_Demo_LCD.bs2") for comparison.· The ONLY DIFFERENCE I can find is that the original demo is setting the time & date vars with a DEBUGIN HEX2 format, and I am setting the vars directly - hardcoding them in the "variables" section of the program, the reason being that I will actually be reading these variables from the variables written to the PINK Server.· The BS2 will then read these variables and set the clock, effectively synchronizing the "slave" clock with the "master" clock at the operator's console.· What the difference is between setting the variables with the DEBUGIN method, vs. simply hardcoding the variables, baffles me.· I have also tried hardcoding the variables in both HEX and DEC ($3B vs. 59, for example).· I am looking to find if there's a way to set as BCD... :-)
I R so confused....
Thanks for your help,
Dave
PS., although this is set up for an LCD, it works just fine without the LCD hooked up if you just use the debug terminal.· I get the same error in display there as with the LCD (so long as I remember to set the right set of output lines (DEBUG vs LCD)).
'
[noparse][[/noparse] VARIABLES THAT WILL BE SET FROM READING CLOCK ON WEB TERMINAL ]---
'[noparse][[/noparse]secs, mins, hrs, date, month, day, year, 0]
year = %00001001 ' Set Year
month = %00000110 ' Set Month
date = %00011000 ' Set Date
day = 5 ' Set Day [noparse][[/noparse]Sun, Mon, Tue, Wed, Thu, Fri, Sat]
hrs = %00010111 ' Set Hours (24 Hour Mode)
mins = %01011001 ' Set Minutes
secs = %01010000 ' Set seconds
GOSUB Set_Time
So all I should need to do is convert each digit of the incoming variable to its BCD equivalent and stick 'em together.· That sounds like a job for BIN8!!!!
WHEW!
Dave
Post Edited (xanatos) : 6/19/2009 12:11:53 AM GMT
You could use this if you need to use DEC format
I do not know if this will help you or not
IF s = 59 THEN
·S = 00
·M = M + 1
·IF M = 59 THEN
·M = 00
·H = H + 1
·IF H = 23 AND M = 58 THEN
·H = 00
·D = D + 1
·ENDIF
·ENDIF
·ENDIF
IF oldsecs <> secs THEN····· ' This Routine Compares the oldsecs to secs
·· oldsecs = secs··········· ' This Routine is so that Counter Update once a Seconds
···
·· S = S + 1················ ' This for the Timer Counter for the amount of time· has that has gone by
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 6/22/2009 9:12:41 PM GMT
The numbers have to be accepted as HEX2, but they are entered as if they were regular decimal.·
So - for any and all of you who scratched their heads over my conundrum, I apologize for not figuring this out sooner and saving you the effort! :-)
Humbled and embarrassed, yet happy I managed to get this figured out...
Dave X
Post Edited (xanatos) : 6/19/2009 2:51:00 AM GMT