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
Posted: Sun Oct 07, 2007 7:52 pm
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
Posted: Mon Oct 08, 2007 4:06 am
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);
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