小编Ant*_*nco的帖子

转换为联合字段产生转换警告

我使用的是Microchip微控制器,它定义了以下结合:

__extension__ typedef struct tagT1CONBITS {
  union {
    struct {
      uint16_t :1;
      uint16_t TCS:1;
      uint16_t TSYNC:1;
      uint16_t :1;
      uint16_t TCKPS:2;
      uint16_t TGATE:1;
      uint16_t :6;
      uint16_t TSIDL:1;
      uint16_t :1;
      uint16_t TON:1;
    };
    struct {
      uint16_t :4;
      uint16_t TCKPS0:1;
      uint16_t TCKPS1:1;
    };
  };
} T1CONBITS;
extern volatile T1CONBITS T1CONbits __attribute__((__sfr__));
Run Code Online (Sandbox Code Playgroud)

在我的代码中的某处我将变量定义为8位无符号整数,我想将其分配给上面联合的一个字段.有点如下:

uint8_t tckps;
// The value of tckps is calculated here by some magic formula
tckps = magicformula();
// We asign the value of tckps to the uC register
T1CONbits.TCKPS = tckps; …
Run Code Online (Sandbox Code Playgroud)

c embedded gcc microchip bit-fields

5
推荐指数
1
解决办法
122
查看次数

标签 统计

bit-fields ×1

c ×1

embedded ×1

gcc ×1

microchip ×1