关于寄存器赋值写法问题

[复制链接]
 楼主| CaLipton 发表于 2018-1-28 15:07 | 显示全部楼层 |阅读模式

pSciRegs->SCICCR.all = 0x0007; // 1 stop bit,  No loopback
    // No parity,8 char bits,
    // async mode, idle-line protocol
对这个寄存器这样写入之后,我的理解不就是SCICCR除了最后一位,其它位都是1,但是这个注释似乎解释的不是这样子,求大家指点
Rospiers 发表于 2018-1-28 15:36 | 显示全部楼层
0x0007 = 0b0000000000000111
Lewisnx 发表于 2018-1-28 15:51 | 显示全部楼层
这个地方后面用了共用体的结构all来对寄存器整体赋值,前面为何直接赋值
CCompton 发表于 2018-1-28 16:05 | 显示全部楼层
是不是BAUD只对应一种配置
Richardd 发表于 2018-1-28 16:22 | 显示全部楼层

siccr对应有几个配置 可以.xx 单个配置 也可以. all同时配置 而baud只对应一个选项 它应该没有下级结构体 当然不用. all这种方法
Mattheww 发表于 2018-1-28 16:42 | 显示全部楼层
它们都是寄存器啊,不是都有八位吗
Erichk 发表于 2018-1-28 17:05 | 显示全部楼层
struct  SCI_REGS {
   union SCICCR_REG     SCICCR;     // Communications control register
   union SCICTL1_REG    SCICTL1;    // Control register 1
   Uint16               SCIHBAUD;   // Baud rate (high) register
   Uint16               SCILBAUD;   // Baud rate (low) register
   union SCICTL2_REG    SCICTL2;    // Control register 2
   union SCIRXST_REG    SCIRXST;    // Recieve status register
   Uint16               SCIRXEMU;   // Recieve emulation buffer register
   union SCIRXBUF_REG   SCIRXBUF;   // Recieve data buffer
   Uint16               rsvd1;      // reserved
   Uint16               SCITXBUF;   // Transmit data buffer
   union SCIFFTX_REG    SCIFFTX;    // FIFO transmit register
   union SCIFFRX_REG    SCIFFRX;    // FIFO recieve register
   union SCIFFCT_REG    SCIFFCT;    // FIFO control register
   Uint16               rsvd2;      // reserved
   Uint16               rsvd3;      // reserved
   union SCIPRI_REG     SCIPRI;     // FIFO Priority control
};


一个是Uint16 另一个是union 当然赋值方式不一样
Thorald 发表于 2018-1-28 17:23 | 显示全部楼层
应该是可以用相同的表述方式吧
Bjorn 发表于 2018-1-28 18:04 | 显示全部楼层
先不说你的代码具体是怎么样的,做个假设下边的代码是一个例子,config和voltage都是uint8长度,config对应有3种配置,分别是转速、重启和电源开关,通过set设置
config是一个联合体,其中的all和set共用一个字节内存,修改all=0就相当于把set中的speed,reset,power都置成0
而config中的voltage只表示电压,用一个数值表示就可以,所以它是uint8_t类型
他没有下一级配置,使用时你直接给他赋一个值就可以了
Rollo 发表于 2018-1-28 18:17 | 显示全部楼层
typedef struct
{
    uint8_t speed:6;//转速
    uint8_t reset:1;//重启
    uint8_t power:1;//电源开关
}Set_t;
typedef union
{
     uint8_t all;
     Set_t set;
}Config_t;
typedef struct
{
  Config_t config;//配置
  uint8_t voltage;//电压
}System_t;

System_t system;
void test(System_t *_system)
{
  _system->config.all = 0x00;//清除配置中的所有设置
  _system->config.set.speed = 50;//设置转速
  _system->config.set.power = 1;//开机
  _system->voltage = 50;//设置电压
}
wangdezhi 发表于 2018-2-2 22:31 | 显示全部楼层
使用与或非。
isseed 发表于 2018-2-2 22:31 | 显示全部楼层
这样就是整体的赋值
xietingfeng 发表于 2018-2-2 22:32 | 显示全部楼层
不是应该后三位吗?
mituzu 发表于 2018-2-2 22:33 | 显示全部楼层
可以使用串口输出看看。
wangdezhi 发表于 2018-2-2 22:33 | 显示全部楼层
楼主是要单独操作吗?
isseed 发表于 2018-2-2 22:33 | 显示全部楼层


pSciRegs->SCICCR.all |= 0x0007
mituzu 发表于 2018-2-2 22:34 | 显示全部楼层
有可能是第2、3位不可写入数据。
xietingfeng 发表于 2018-2-2 22:34 | 显示全部楼层
楼主读取的哪个寄存器?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

126

主题

369

帖子

0

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