|
|
View previous topic :: View next topic |
Author |
Message |
Don_J
Joined: 13 Apr 2005 Posts: 7
|
DS1307 Set Command need help |
Posted: Tue Nov 04, 2008 9:51 am |
|
|
I am trying to write a pgm to set the ds1307 interactively from a serial connection. I want to print a request, wait for input (two digits) and update the variable. I would repeat this for the year, month, day, dow, hr, min, and sec. I tried using the gethex to input the digits. The problem is when I pass this to the DS1307 it sets the wrong time. If I set the variables manually (BYTE sec=22, as an example it works OK).
Does anyone have code to set the ds1307 interactively via a serial connection?
I am using the PCWHD version 4.073 and the processor is a 16F886.
The following is a snip of the code I was using:
Code: | BYTE sec;
BYTE min;
printf("\r\n\Enter 2 digits for the Seconds = ");
sec=gethex();
printf("\r\n\Enter 2 digits for the Minutes = ");
min=gethex();
ds1307_set_date_time(29,10,98,04,16,min,sec); |
|
|
|
Ttelmah Guest
|
|
Posted: Tue Nov 04, 2008 10:55 am |
|
|
The 'set_date_time' function, contains code to convert the incoming numbers into_ the BCD format needed by the chip.
22Hex (which is what gethex will read the value '22' as), is 34 decimal. The time will get set to 34 minutes, not 22 minutes using this code.
You either need to just read the value as ASCII, perform a conversion from BCD hex to decimal with the existing code, or use your own version of the set_date_time function, that does not perform the BCD conversion.
Best Wishes |
|
|
Don_J
Joined: 13 Apr 2005 Posts: 7
|
DS1307 Set Command need help |
Posted: Tue Nov 04, 2008 11:30 am |
|
|
Thank you! That's great. I modified the driver and it works.
Where would I find more info on this "perform a conversion from BCD hex to decimal "? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Nov 04, 2008 12:33 pm |
|
|
Don_J wrote: | Where would I find more info on this "perform a conversion from BCD hex to decimal "? | For example, in the same location where you found the driver to write to the DS1307...
It looks like your driver comes out of this thread: http://www.ccsinfo.com/forum/viewtopic.php?t=23255
Scroll a bit down and you will find the functions bin2bcd() and bcd2bin().
Or use the search function of this forum...
More examples:
A version with multiply and mod, short notation, large code.
A version using shifts instead of multiply. Longer notation but faster code on a PIC16 which has no hardware multiply. |
|
|
Don_J
Joined: 13 Apr 2005 Posts: 7
|
|
Posted: Tue Nov 04, 2008 12:48 pm |
|
|
Thanks so much, you have been a big help. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|