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

BCD to binary

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



Joined: 02 Nov 2003
Posts: 18

View user's profile Send private message Visit poster's website

BCD to binary
PostPosted: Sat Apr 10, 2004 8:38 pm     Reply with quote

I have created a conversion between BCD to binary so that I can manage data from a DS1307 RTC a little easier. When I use the following function, it usually returns zero. I also have a binary to BCD conversion, but it seem to work okay. Any feedback would be helpful.

Code:

read_RTC();
for(i=2;i>0;i--)
    {
       time[i]=bcd2bin(RTC_time[i]);
    }

byte bcd2bin(byte bcd_val)
{
 byte bin_val;
  while(bcd_val>=0x10)
    {
      bin_val+=10;
      bcd_val-=0x10;
    }
  bin_val+=bcd_val;
  return(bin_val);
}


Thanks

Ed Arnold
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 10, 2004 11:35 pm     Reply with quote

If you're searching for a bcd2bin() function, there's one at the end of this
thread, that avoids the use of the multiply routine.
http://www.ccsinfo.com/forum/viewtopic.php?t=18830&highlight=bcd2bin

There's another one at the end of this thread that uses multiply.
If code space is not a worry, then it has fewer lines of code than
the one above:
http://www.ccsinfo.com/forum/viewtopic.php?t=17668&highlight=bcd2bin
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