View previous topic :: View next topic |
Author |
Message |
dxrose86
Joined: 28 Feb 2009 Posts: 5 Location: Taunton Ma
|
Unions version 2 |
Posted: Thu Jan 21, 2010 1:47 pm |
|
|
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
|
|
Posted: Thu Jan 21, 2010 2:26 pm |
|
|
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
|
|
Posted: Thu Jan 21, 2010 3:30 pm |
|
|
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? |
|
|
|