c语言.h头文件的一些问题

[复制链接]
919|1
 楼主| longchijie 发表于 2016-11-10 11:34 | 显示全部楼层 |阅读模式
下面是在.h 头文件里对一个32位寄存器的定义,有些地方不明白,  请教一下,先谢谢啦!
1)为什么这里typedef union有4个 struct? 是不是针对不同情况?如果我使用第一个struct,就不能用其他的么?
2)如果我对某一位赋值,我可以使用, 比如PMCONbits.CS2P=1;(因为定义了unsigned CS2P:1;)
但是有些位没有定义,比如unsigned:1;是不是说明该位不能被赋值?如果能,怎么赋值?
3) 能不能用PMCON对整个寄存器赋值,比如PMCON=0xFFFFFF00
4)    PMCONCLR是不是所有为置0, PMCONSET所有为置1?




#define PMCON PMCON
extern volatile unsigned int   PMCON __attribute__((section("sfrs")));
typedef union {
  struct {
    unsigned RDSP:1;
    unsigned WRSP:1;
    unsigned :1;
    unsigned CS1P:1;
    unsigned CS2P:1;
    unsigned ALP:1;
    unsigned CSF:2;
    unsigned PTRDEN:1;
    unsigned PTWREN:1;
    unsigned PMPTTL:1;
    unsigned ADRMUX:2;
    unsigned SIDL:1;
    unsigned :1;
    unsigned ON:1;
    unsigned :1;
    unsigned DUALBUF:1;
    unsigned :5;
    unsigned RDSTART:1;
  };
  struct {
    unsigned :6;
    unsigned CSF0:1;
    unsigned CSF1:1;
    unsigned :3;
    unsigned ADRMUX0:1;
    unsigned ADRMUX1:1;
  };
  struct {
    unsigned :13;
    unsigned PSIDL:1;
    unsigned :1;
    unsigned PMPEN:1;
  };
  struct {
    unsigned w:32;
  };
} __PMCONbits_t;
extern volatile __PMCONbits_t PMCONbits __asm__ ("PMCON") __attribute__((section("sfrs")));
extern volatile unsigned int        PMCONCLR __attribute__((section("sfrs")));
extern volatile unsigned int        PMCONSET __attribute__((section("sfrs")));
extern volatile unsigned int        PMCONINV __attribute__((section("sfrs")));

sdnumcu 发表于 2016-11-15 22:47 | 显示全部楼层
头文件........你想明白啥
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

7

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部