Bitfield for Kinetis

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

Bitfield for Kinetis

513 Views
MAPC
Senior Contributor I

Is there a way to make a bitfield structure for K22 in KDS?

Labels (1)
0 Kudos
2 Replies

327 Views
TICS_Fiona
NXP Employee
NXP Employee

Hello Macro

I tested in KDS 3.0 and defined the bitfield structure as below:

union {

       unsigned char bits;

       struct {

                  unsigned char bit0 :     1;

                  unsigned char bit1 :     1;

                  unsigned char bit2 :     1;

                  unsigned char bit3 :     1;

                  unsigned char bit4 :     1;

                  unsigned char bit5 :     1;

                  unsigned char bit6 :     1;

                  unsigned char bit7 :     1;

                }R;

} Test_bit;

And access it in code as:

Test_bit.R.bit7=1;

This works as on other C compiler.

Best Regards

Fiona Kuang

Technical Information & Commercial Support

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Mark Correct button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

327 Views
egoodii
Senior Contributor III

What are the resulting assembly-level instructions for the C-source 'Test_bit.R.bit7=1;'?  I.e., what is the code-cost for packing density?

0 Kudos