DS1307 hex display on sertxd

vk6kci

New Member
I need a fix to display the output of the DS1307 RTC as hex when outputting to sertxd or the serial terminal (F8). I have just started playing with the DS1307 and am currently getting the output as decimal. thanx. M.
 

Technical

Technical Support
Staff member
The DS1307 works with binary coded decimal. If you use debug rather than sertxd, and view the hex debug printout - this will give you the time as it looks in 'normal life'.

e.g. $12 $30 for 12:30pm
 

vk6kci

New Member
Thanks...

Debug shows the realtime values in the hex column, but I need a little more than that.

I need to timestamp data that is being collected via sensors and need to dispay that on the terminal window as comma delimited data. The timestamp currently displays as decimal in the terminal window. Do I need a small routine to convert the data to normal clock display?
 

Technical

Technical Support
Staff member
This will output the CSV text in same format as debug (presuming data in b1 to start with)

b2 = b1 and $F0 + $30
b3 = b1 and $0F + $30

sertxd ("$",b2,b3)

Basically you mask each nibble and then add $30 to change to ascii

Edited by - Technical on 2/8/2006 1:52:46 PM
 

vk6kci

New Member
Just spent about an hour trying to figure out why I got 0-9 in the 1's column and 0, @, P, '0, p, and the euro symbol in the tens column. Even went back to my old dig textbooks (Tocci) to refresh on binary anding and adding. I finaly gave up and came back to the forum to post a large question mark. And.... there it was.... the corrected answer! The up side is that I got to review some stuff that I should have remembered from my college days. I think it worked out better that way, because now I know why it works rather than just grabbing the code and using it in ignorance. Thanks very much for the assistance. I think you will be seeing more from me in the future.
 

vk6kci

New Member
Yes.... it does work BUT..

It uses up a lot of variables considering that the seconds, minutes, hours, date and month require 2 variables each. The readi2c command also uses another 7. I dont need all of them for what I am doing, but... is there any way to reduce the amount of variables?
 

Technical

Technical Support
Staff member
Sorry about the mistake.
If you don't need a variable just repeat a dummy variable in the readi2c - e.g. to ignore all the b1's.

readi2c 0,(b1,b1,b1,b1,b4,b5)

You can also use a sub to do the transmission - you then use the same three variables every time

let b1 = b4
gosub trans

let b1 = b5
gosub trans

rest of code...


trans:
b2 = b1 \ $10 + $30
b3 = b1 and $0F + $30
sertxd ("$",b2,b3)
return


Edited by - Technical on 2/9/2006 1:25:44 PM
 

BarryP

Senior Member
Howdy
Due to the limited number of GP Variables , I tend to use Peek/Poke a LOT.
Define a few Standard variables that are of unknown state when used in gosubs etc , But allways available.
I.E.

Symbol mRTCbase = $70
Symbol mSecs = mRTCbase
Symbol mMins = mRTCbase + 1
Symbol mHour = mRTCbase + 2
Symbol mDay = mRTCbase + 3
Symbol mDate = mRTCbase + 4
Symbol mYear = mRTCbase + 5
Symbol mRTCctl = mRTCbase + 6
symbol mLastSecs = mRTCbase + 7
Symbol X = B?
Symbol Y = B?
Symbol I = B?
;*********
ReadClock:
;*********
i2cslave %11010000, i2cslow ,i2cbyte
Peek mSecs,X
Poke mLastSecs,X
For X = 0 to 6
readi2c X,(I)
Y = X + mSecs ;mRTCbase
Poke Y,I
next
Return

Edited by - barryp on 2/10/2006 3:04:05 AM
 
Top