位定义方法定义寄存器

寄存器“位域”定义的语法格式:

Struct 位域结构名
{
    类型说明符  位域名1:位域长度
    类型说明符  位域名2:位域长度
    ...
    类型说明符  位域名n:位于长度
}
//从右到左申明的
//位域的申明不能横跨两个字节
//位域名可以没有,调整作用
struct  SCICCR_BITS {        // bit    description
   Uint16 SCICHAR:3;         // 2:0    Character length control        
   Uint16 ADDRIDLE_MODE:1;   // 3      ADDR/IDLE Mode control
   Uint16 LOOPBKENA:1;       // 4      Loop Back enable
   Uint16 PARITYENA:1;       // 5      Parity enable   
   Uint16 PARITY:1;          // 6      Even or Odd Parity
   Uint16 STOPBITS:1;        // 7      Number of Stop Bits
   Uint16 rsvd1:8;           // 15:8   reserved
}; 


union SCICCR_REG {
   Uint16              all;
   struct SCICCR_BITS  bit;
};
union
SCICCR_REG SCICCR;
SCICCR.all=0x007F;
SCICCR.bit.SCICHAR=5;
//结构体与共同体的区别:共同体共用一个存储空间。

原文地址:https://www.cnblogs.com/wy9264/p/11409020.html