In your code, where do you convert your values to HEX?
I could not find it, or see it.
(May be it is me...ohh these days I am feeling older (and elder) every passing second. )
-----------------
In your code, where do you convert your values to HEX?
I could not find it, or see it.
(May be it is me...ohh these days I am feeling older (and elder) every passing second. )
-----------------
good point I what is the best way to convert it Hours = #Hours ?
would that work?
I apologise for my ignorance but I have just started with picbasic pro.
kind regards John
Hi,
As far as I remember the RTC holds the time in packed BCD format. That is the upper nibble is the tens and the lower nibble is the unit. So the formula to convert it would be
Real_Hours = (10* hour_tens)+ hour_units
In PBP this would be :
Where CLOCK_TMP1 is a temporary variable. You can do it in one line to. I broke up the thing to make it more readableCode:CLOCK_TMP1 = (HOURS >> 4) * 10 ' PROCESS 10s BCD HOURS = HOURS & %00001111 ' PROCESS 1s BCD HOURS = CLOCK_TMP1+ HOURS ' ADD BOTH TO GET BINARY
While working on a PCF8563 RTC chip I noticed that the unused bits in the memory map are not always "zero". Thus it is good idea to shred off the bits not used and make them zero manually. Like:
Happy New YearCode:HOURS = HOURS & %00111111 ' clear unused bits MINUTES = MINUTES & %01111111 ' clear unused bits
Regards
Sougata
In addition to sougata's, here is a conversion from Melanie's.
You need to convert your decimal values to HEX values and then you can write the HEX values to your RTC chip.
Code:DecVal = HOUR GOSUB ConvertBCD HOUR = HEXVal 'Now you set your RTC chip with this new HOUR variable (which is now in HEX). ConvertBCD: HEXVal = DecVal DIG 1 HEXVal = HEXVal <<4 HEXVal = HEXVal + DecVal DIG 0 RETURN
----------------
Edit: also take a look at this post here: http://www.picbasic.co.uk/forum/showthread.php?t=110
Last edited by sayzer; - 30th December 2006 at 10:30.
Thanks again Guy's got the clock working fine writing and reading from the RTC chip.
Bookmarks