首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

怎样声明位变量?

如果是汇编,就按照楼上所说的用bset指令
如果是C,可以参照CW中Wizard生成的结构
typedef union {
  byte Byte;
  struct {
    byte PTA0    :1;           /* Port A Data Bit 0, Keyboard Input */
    byte PTA1    :1;           /* Port A Data Bit 1, Keyboard Input */
    byte PTA2    :1;           /* Port A Data Bit 2, Keyboard Input */
    byte PTA3    :1;           /* Port A Data Bit 3, Keyboard Input */
    byte PTA4    :1;           /* Port A Data Bit 4, Keyboard Input */
    byte PTA5    :1;           /* Port A Data Bit 5, Keyboard Input */
    byte PTA6    :1;           /* Port A Data Bit 6, Keyboard Input */
    byte PTA7    :1;           /* Port A Data Bit 7, Keyboard Input */
  } Bits;
  struct {
    byte PTA     :8;
  } MergedBits;
} PTASTR;
extern volatile PTASTR _PTA @0x00000000;
#define PTA _PTA.Byte
#define PTA_PTA0 _PTA.Bits.PTA0
#define PTA_PTA1 _PTA.Bits.PTA1
#define PTA_PTA2 _PTA.Bits.PTA2
#define PTA_PTA3 _PTA.Bits.PTA3
#define PTA_PTA4 _PTA.Bits.PTA4
#define PTA_PTA5 _PTA.Bits.PTA5
#define PTA_PTA6 _PTA.Bits.PTA6
#define PTA_PTA7 _PTA.Bits.PTA7
#define PTA_PTA _PTA.MergedBits.PTA
返回列表