I am trying to set up the internal registers of a HCS12 processor using unions. Here is the way I currently have the unions:
union byte{
struct{
unsigned int B0: 1;
unsigned int B1: 1;
unsigned int B2: 1;
unsigned int B3: 1;
unsigned int B4: 1;
unsigned int B5: 1;
unsigned int B6: 1;
unsigned int B7: 1;
}idv;
unsigned int All: 8;
};
union allPurpose{
struct {
union byte A;
union byte B;
} AB;
unsigned int D: 16;
};
The issue is that when I initialize A to 170 and B to 187 using the int All. D should be 43,707 but is 170. I know that nested unions work but for some reason it is not working. If anyone can see something wrong and can help it would be appreciated.
Edit: Here is the code that is using the union in.
HCS12.accumulator.AB.A.All=0xAA;
HCS12.accumulator.AB.B.All=0xBB;
printf("\nReg A: %d",HCS12.accumulator.AB.A.All);
printf("\nReg B: %d",HCS12.accumulator.AB.B.All);
printf("\nReg D: %d",HCS12.accumulator.D);
The Union allPurpose is just in a another structure.