[MCU] 寄存器赋值

[复制链接]
 楼主| spark周 发表于 2020-2-22 23:04 | 显示全部楼层 |阅读模式

pSciRegs->SCICCR.all = 0x0007; // 1 stop bit,  No loopback
    // No parity,8 char bits,
    // async mode, idle-line protocol
对这个寄存器这样写入之后,我的理解不就是SCICCR除了最后一位,其它位都是1,但是这个注释似乎解释的不是这样子,求大家指点
hanwe 发表于 2020-2-22 23:07 | 显示全部楼层

0x0007 = 0b0000000000000111
wangpe 发表于 2020-2-22 23:10 | 显示全部楼层
这个地方后面用了共用体的结构all来对寄存器整体赋值,前面为何直接赋值
gongche 发表于 2020-2-22 23:12 | 显示全部楼层
是不是BAUD只对应一种配置
zhanglli 发表于 2020-2-22 23:14 | 显示全部楼层
siccr对应有几个配置 可以.xx 单个配置 也可以. all同时配置 而baud只对应一个选项 它应该没有下级结构体 当然不用. all这种方法
tian111 发表于 2020-2-22 23:16 | 显示全部楼层
它们都是寄存器啊,不是都有八位吗
juventus9554 发表于 2020-2-22 23:19 | 显示全部楼层

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 当然赋值方式不一样
dingy 发表于 2020-2-22 23:20 | 显示全部楼层
应该是可以用相同的表述方式吧
xxrs 发表于 2020-2-22 23:22 | 显示全部楼层

先不说你的代码具体是怎么样的,做个假设下边的代码是一个例子,config和voltage都是uint8长度,config对应有3种配置,分别是转速、重启和电源开关,通过set设置
zhaoxqi 发表于 2020-2-22 23:24 | 显示全部楼层
config是一个联合体,其中的all和set共用一个字节内存,修改all=0就相当于把set中的speed,reset,power都置成0
pangb 发表于 2020-2-22 23:26 | 显示全部楼层
而config中的voltage只表示电压,用一个数值表示就可以,所以它是uint8_t类型
ousj 发表于 2020-2-22 23:28 | 显示全部楼层
他没有下一级配置,使用时你直接给他赋一个值就可以了
zyf部长 发表于 2020-2-22 23:31 | 显示全部楼层
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;//设置电压
}
dengdc 发表于 2020-2-22 23:34 | 显示全部楼层

使用与或非。
zhuww 发表于 2020-2-22 23:37 | 显示全部楼层

这样就是整体的赋值
gongche 发表于 2020-2-22 23:40 | 显示全部楼层
不是应该后三位吗?
bqyj 发表于 2020-2-22 23:43 | 显示全部楼层
可以使用串口输出看看。
songqian17 发表于 2020-2-22 23:45 | 显示全部楼层
楼主是要单独操作吗?
chuxh 发表于 2020-2-22 23:47 | 显示全部楼层
pSciRegs->SCICCR.all |= 0x0007
wenfen 发表于 2020-2-22 23:49 | 显示全部楼层
有可能是第2、3位不可写入数据。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

821

主题

10121

帖子

4

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