CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DS1307 Set Command need help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Don_J



Joined: 13 Apr 2005
Posts: 7

View user's profile Send private message

DS1307 Set Command need help
PostPosted: Tue Nov 04, 2008 9:51 am     Reply with quote

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







PostPosted: Tue Nov 04, 2008 10:55 am     Reply with quote

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

View user's profile Send private message

DS1307 Set Command need help
PostPosted: Tue Nov 04, 2008 11:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 04, 2008 12:33 pm     Reply with quote

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... Rolling Eyes

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

View user's profile Send private message

PostPosted: Tue Nov 04, 2008 12:48 pm     Reply with quote

Thanks so much, you have been a big help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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