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 Question

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



Joined: 04 Oct 2007
Posts: 14

View user's profile Send private message

DS1307 Question
PostPosted: Sun Oct 07, 2007 7:41 pm     Reply with quote

referring to the data sheet,if I am not wrong it says that the data that will be retrieved is binary coded decimals so e.g 10 in binary is 00010000. I hope I am correct. How do we write and assign values in the RTC register?should it normally be decimals or we will format it to BCD?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 07, 2007 7:52 pm     Reply with quote

See this DS1307 driver in the CCS Code Library.
http://www.ccsinfo.com/forum/viewtopic.php?p=46052
Note that it uses bin2bcd() and bcd2bin() conversions when writing or
reading from the DS1307 date/time registers.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Oct 08, 2007 4:06 am     Reply with quote

Ten in bcd is encoded as 00010000 in an 8 bit storage location eleven would be 00010001. That means the high nibble which in pure binary represents sixteen times the numerical weight of the low nibble now only represents ten times the weight in bcd. A routine like the following takes advantage of the fact that ten is eight plus two and eight and two divisions are equivalent to shifting.
Code:
int8 bcdtointeger(int8 bcd)
{int8 tmp;

tmp=bcd;
//// high nibble is 16 times the value
tmp=tmp>>1; /// tmp1 is now 8 times
tmp=tmp & 0x78;
tmp=tmp+(tmp>>2); // 8 times plus tmp2>> is now 2 times
tmp=tmp+ (bcd & 0x0F);

return (tmp);
}
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