#include "stdio.h"
#include "string.h"
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef union
{
struct xxICn_Tag
{
volatile uint16_t PRI : 4;
volatile uint16_t unsed1 : 3;
volatile uint16_t MK : 1;
volatile uint16_t unsed2 : 4;
volatile uint16_t IF : 1;
volatile uint16_t unsed3 : 3;
}F;
volatile uint16_t U16;
}xxICn_T;
int main()
{
xxICn_T T,*P;
P=&T;
memset(P,0,sizeof(T));
T.F.PRI=5;
T.F.MK=1;
T.F.IF=1;
printf("%d %d %d \n",T.F.PRI,T.F.MK,T.F.IF);
printf("0x%x",T.U16);
system("pause");
}
result:T.U16=0x1085.位段定义,调用整个寄存器值时,要首先对整个寄存器清零。