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 CCS Technical Support

Unions version 2

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



Joined: 28 Feb 2009
Posts: 5
Location: Taunton Ma

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

Unions version 2
PostPosted: Thu Jan 21, 2010 1:47 pm     Reply with quote

Processor Pic18f26K20
Compiler version 4.099

Problem: I am trying to use bit fields inside a union.
My program looks like

Code:
union {
int1 bright1;
int1 bright2;
int1 bright3;
int1 bright4;
int1 bright5;
int1 bright6;
int1 functionb1;
int1 notused1b7;
int8 bytem;
}msgd;

void main ()
 {
  msgd.bytem = 0xaa;
 

  if (msgd.functionb1 == 1)
    msgd.functionb1 = 0;

}

/* end of program */

The bit field accessess bit 6 of the byte field. but generates the following code:
Code:

116:                     if (msgd.functionb1 == 1)
 
02F4    A176             BTFSS 0x76, 0, BANKED
 
02F6    D001             BRA 0x2fa
117:
                                msgd.functionb1 = 0;
 
02F8    9176     BCF 0x76, 0, BANKED

The generated code will access bit 0 only no matter what bit field I try.
any suggestions would be appreciated.
Thanks
_________________
Micro-guy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 2:26 pm     Reply with quote

See Ttelmah's example of bitfields in a union here:
http://www.ccsinfo.com/forum/viewtopic.php?t=28773&start=3

Also, please don't start a new thread every time you have a new
question on Unions. Add the question onto your existing thread.
The thread will "bump" to the top of the list. We will see it, and
it will be noticed.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 3:30 pm     Reply with quote

Quote:
The generated code will access bit 0 only no matter what bit field I try.
That's exactly, what you should expect from a union, you possibly mean a struct instead?
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