struct variable access

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

struct variable access

2,400 Views
ScottC
Contributor I
I am using the following and can'y access the variable flags1.  I can only change bits
 
Also, the struct defaults to 2 byte.  I can't seem to change it to 1 byte.  I'm new to C.
 
Thanks,
 
 
struct
      {
       byte flow0              :1;     /* b0 */
       byte flow1              :1;     /* b1 */
       byte temp0              :1;     /* b2 */
       byte temp1              :1;     /* b3 */
       byte pres0              :1;     /* b4 */
       byte pres1              :1;     /* b5 */
       byte reverse            :1;     /* b6 */
       byte capfont            :1;     /* b7 */
       byte ampm24             :1;     /* b8 */
       byte h24                :1;     /* b9 */
       byte underline          :1;     /* b10 */
       byte volstd             :1;     /* b11 */
       byte pwrsav             :1;     /* b12 */
       byte baklit             :1;     /* b13 */
       byte mdyform            :1;     /* b14 */
       byte magnify            :1;     /* b15 */
      }
flags1;
#define flow0 flags1.flow0
#define flow1 flags1.flow1
#define temp0 flags1.temp0
#define temp1 flags1.temp1
#define reverse flags1.reverse
#define pres0 flags1.pres0
#define pres1 flags1.pres1
#define capfont flags1.capfont
#define ampm24 flags1.ampm24
#define h24 flags1.h24
#define underline flags1.underline
#define volstd flags1.volstd
#define pwrsav flags1.pwrsav
#define baklit flags1.baklit
#define mdyform flags1.mdyform
#define magnify flags1.magnify
Labels (1)
0 Kudos
Reply
1 Reply

576 Views
UK_CF_FAE
NXP Employee
NXP Employee
Hi Scott,
 
Yes, I see your problem. Your structure is declared correctly, but this is a bit-field type declaration. What you have declared is a bit-field with 16 entries, so the compiler uses an integer (ie 16-bits, 2 bytes) to store the bit field. The fact that you need to use the storage class 'byte' to represent the datatype "bit" ie byte flow : 1 is a relic of C, I'm afraid.
 
If you abandon the entries 8-15, you'll find CW uses a byte for this bit-field.
 
Look at the "device".h files - eg mc9s08qb8.h and you'll see plenty of these bit-fields where we have defined the registers of the device.
 
Mark.
0 Kudos
Reply