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 can i concate the 8 bits of the struc to one var

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



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

How can i concate the 8 bits of the struc to one var
PostPosted: Sun Sep 03, 2006 1:26 pm     Reply with quote

// Defines seconds register (RESET STATE: ???? ????)
struct {
byte UNITS_BCD :4; // Unit seconds BCD format
byte TENS :3; // Ten seconds, 0 to 5 binary
byte NOT_UNUSED :1; // NOT USED
} SECONDSREG;

time[0]=hexd2decD(SECONDSREG.TENS);
time[1]=hexd2decD(SECONDSREG.UNITS_BCD);

Now there are two 8 bit vars (time[0]+time[1])
How can i put these together on one var (time[0])
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 03, 2006 1:35 pm     Reply with quote

See the make16() function in the CCS manual.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 03, 2006 1:41 pm     Reply with quote

Thats make an 16bit value

But i need an 8bit var

UNITS_BCD = 4 bit
TENS = 3 bit
NOT USED = 1 bit

I will concate the 3 types together and put it in an 8 bit variable
time[0]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 03, 2006 2:25 pm     Reply with quote

OK, I guess I misread your post.

It looks like you could use bcd2bin() to convert SECONDSREG to
an 8-bit integer. Example:
Code:

int8 result;

result = bcd2bin(SECONDSREG);



Code:
// This function converts an 8 bit BCD value to
// an 8 bit binary value.
// The input range must be from 00 to 99.

char bcd2bin(char bcd_value)
{
char temp;

temp = bcd_value;

// Shifting the upper digit right by 1 is
// the same as multiplying it by 8.
temp >>= 1;

// Isolate the bits for the upper digit.
temp &= 0x78;

// Now return: (Tens * 8) + (Tens * 2) + Ones
return(temp + (temp >> 2) + (bcd_value & 0x0f));

}
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