c语言定义92bit位变量,IAR中 C语言位定义



__IO_REG8_BIT( SYS,             0xFFFFF802, __READ_WRITE )

#define __IO_REG8_BIT(NAME, ADDRESS, ATTRIBUTE)                 \

__near __no_init volatile ATTRIBUTE union \

{                                       \

unsigned char NAME;                   \

__BITS8 NAME ## _bit;                 \ // ## _bit ?? ## 可以连接前后

//比如 NAME 是 a,这句就//是    __BITS8   a_bit;

} @ ADDRESS;

typedef struct

{

unsigned char no0:1;

unsigned char no1:1;

unsigned char no2:1;

unsigned char no3:1;

unsigned char no4:1;

unsigned char no5:1;

unsigned char no6:1;

unsigned char no7:1;

} __BITS8;

__near

Syntax Follows the generic syntax rules for memory type attributes that can be used on data

objects, see Type attributes, page 193.

Description The __near memory attribute overrides the default storage of variables given by the

selected data model and places individual variables and constants in near memory. You

can also use the __near attribute to create a pointer explicitly pointing to an object

located in the near memory.

Storage information Address range: 0x0-07FFF and 0xFFFF8000-0xFFFFFFFF (64 Kbytes)

Example __near int x;

See also Memory types, page 13.

__no_init

Syntax Follows the generic syntax rules for object attributes, see Object attributes, page 195.

Description Use the __no_init keyword to place a data object in non-volatile memory. This means

that the initialization of the variable, for example at system startup, is suppressed.

Example __no_init int myarray[10];

#define PRERR             SYS_bit.no0

在stdbool.h中,定义了一个位宏,如果需要变量定义,就是如下: bool abit; abit就是一个位变量了,这种方法简单,但是在多个位的时候不好处理,比如需要一批位变量 初始化的时候。 还可以采用如下方法: typedef struct {     unsigned char no0:1;     unsigned char no1:1;     unsigned char no2:1;     unsigned char no3:1;     unsigned char no4:1;     unsigned char no5:1;     unsigned char no6:1;     unsigned char no7:1; } __BIT8 ; volatile union { unsigned char strack; __BIT8 strack_bit; } ; union { unsigned char sk; __BIT8 sk_bit; } ; 定义位: #define mflag        strack_bit.no0 volatile union { unsigned char strack; __BIT8 strack_bit; } ; 中加上VOLATILE,如果发现给编译器优化掉,就一定要加上, strack 就是一个可按位操作的变量, strack=0;就可以把所有8个位全部清零,比起BOOL方便一些。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值