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

How i conversion int32 to BCD?

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







How i conversion int32 to BCD?
PostPosted: Wed Jan 05, 2005 5:54 am     Reply with quote

I have int32 variable and i want to convert it for display on 7-segment X 5 digit (00000-99999)

How i conversion int32 to BCD?

pls.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jan 05, 2005 6:51 am     Reply with quote

Code:
//-----------------------------------------------------------------------------
// Converts a single BCD-character to an int8.
//-----------------------------------------------------------------------------
int8 Int2Bcd(int8 val)
{
  return ((val / 10) << 4) + (val % 10);
}

//-----------------------------------------------------------------------------
// Converts a single BCD-character to an int8.
//-----------------------------------------------------------------------------
int8 Bcd2Int(int8 BCD)
{
  return (10 * (BCD >> 4)) + (BCD & 0x0F);
}


For an int32 you'l l have to call these functions 4 times, for example
Code:
int8 bcd, i;
int32 LargeValue;

for (i=4; i!=0; i--)
{
  bcd = int2bcd( make8(LargeValue, i-1) );
  putc(bcd);         // Send to LCD
)
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