定义了一个共用体
//test
typedef union
{
uint16_t u16Word1All;
struct
{
//bit8-15
uint16_t bRes15 :1;//
uint16_t bRes14 :1;//
uint16_t bRes13 :1;//
uint16_t bRes12 :1;//
uint16_t bRes11 :1;//
uint16_t bRes10 :1;//
uint16_t bRes9 :1;//
uint32_t bRes8 :1;//
uint32_t bRes7 :1;//
uint32_t bRes6 :1;//
uint32_t bRes5 :1;//
uint32_t bRes4 :1;//
uint32_t bRes3 :1;//
uint32_t bRes2 :1;//
uint32_t bRes1 :1;//
uint32_t bRes0 :1;//
}Bits;
}_unTestDef_t;
_unTestDef_t unTest;
unTest.u16Word1All = 0x0001;
LOG_INFO("u16=0x%x",unTest.u16Word1All);
LOG_INFO("bit[0]=%d",unTest.Bits.bRes0);
LOG_INFO("bit[1]=%d",unTest.Bits.bRes1);
LOG_INFO("bit[2]=%d",unTest.Bits.bRes2);
LOG_INFO("bit[3]=%d",unTest.Bits.bRes3);
LOG_INFO("bit[4]=%d",unTest.Bits.bRes4);
LOG_INFO("bit[5]=%d",unTest.Bits.bRes5);
LOG_INFO("bit[6]=%d",unTest.Bits.bRes6);
LOG_INFO("bit[7]=%d",unTest.Bits.bRes7);
LOG_INFO("bit[8]=%d",unTest.Bits.bRes8);
LOG_INFO("bit[9]=%d",unTest.Bits.bRes9);
LOG_INFO("bit[10]=%d",unTest.Bits.bRes10);
LOG_INFO("bit[11]=%d",unTest.Bits.bRes11);
LOG_INFO("bit[12]=%d",unTest.Bits.bRes12);
LOG_INFO("bit[13]=%d",unTest.Bits.bRes13);
LOG_INFO("bit[14]=%d",unTest.Bits.bRes14);
LOG_INFO("bit[15]=%d",unTest.Bits.bRes15);
unTest.u16Word1All = 0xF000;
LOG_INFO("u16=0x%x",unTest.u16Word1All);
LOG_INFO("bit[0]=%d",unTest.Bits.bRes0);
LOG_INFO("bit[1]=%d",unTest.Bits.bRes1);
LOG_INFO("bit[2]=%d",unTest.Bits.bRes2);
LOG_INFO("bit[3]=%d",unTest.Bits.bRes3);
LOG_INFO("bit[4]=%d",unTest.Bits.bRes4);
LOG_INFO("bit[5]=%d",unTest.Bits.bRes5);
LOG_INFO("bit[6]=%d",unTest.Bits.bRes6);
LOG_INFO("bit[7]=%d",unTest.Bits.bRes7);
LOG_INFO("bit[8]=%d",unTest.Bits.bRes8);
LOG_INFO("bit[9]=%d",unTest.Bits.bRes9);
LOG_INFO("bit[10]=%d",unTest.Bits.bRes10);
LOG_INFO("bit[11]=%d",unTest.Bits.bRes11);
LOG_INFO("bit[12]=%d",unTest.Bits.bRes12);
LOG_INFO("bit[13]=%d",unTest.Bits.bRes13);
LOG_INFO("bit[14]=%d",unTest.Bits.bRes14);
LOG_INFO("bit[15]=%d",unTest.Bits.bRes15);