Bitfield for Kinetis

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Bitfield for Kinetis

1,002 次查看
MAPC
Senior Contributor I

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

标签 (1)
0 项奖励
回复
2 回复数

816 次查看
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 项奖励
回复

816 次查看
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 项奖励
回复