__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

以下转自http://renesasrulz.spaces.eepw.com.cn/articles/article/item/69883

在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方便一些。

IAR中 C语言位定义的更多相关文章

  1. C语言中的按位移动及其简单引用

    C语言中的按位移动及其简单应用 在C语言中按位左移用”<<”表示,按位右移用”>>”表示. 按位左移和按位右移运算经常被用来替换乘二和除二运算,但是要注意,这两者之间并不完全等 ...

  2. C语言编程中函数指针的定义及使用

    C语言中函数指针的定义: typedef int (*funcPtr)(int, int)表示定义了一个函数指针funcPtr,这个函数指针只能指向如下: int add(int, int).int ...

  3. Python语言中的按位运算

    (转)位操作是程序设计中对位模式或二进制数的一元和二元操作. 在许多古老的微处理器上, 位运算比加减运算略快, 通常位运算比乘除法运算要快很多. 在现代架构中, 情况并非如此:位运算的运算速度通常与加 ...

  4. 【C语言】求两个数中不同的位的个数

    //求两个数中不同的位的个数 #include <stdio.h> int count_different(int a, int b) { int count = 0; int c = a ...

  5. 浅谈单片机中C语言与汇编语言的转换

    做了一单片机设计,要用C语言与汇编语言同时实现,现将这次设计的感受和收获,还有遇到的问题写下,欢迎感兴趣的朋友交流想法,提出建议. 单片机设计:基于51单片机的99码表设计 软件环境:Proteus8 ...

  6. 编程实践中C语言的一些常见细节

    对于C语言,不同的编译器采用了不同的实现,并且在不同平台上表现也不同.脱离具体环境探讨C的细节行为是没有意义的,以下是我所使用的环境,大部分内容都经过测试,且所有测试结果基于这个环境获得,为简化起见, ...

  7. 小心C语言的定义与声明

    小心C语言的定义与声明 转自360博客 注:为便于说明问题,文中提及的变量和函数都被简化. 一.起源 DBProxy在测试过程中,发现对其执行某步管理操作后,程序有时会崩溃,但不是每次都出现. 二.G ...

  8. c语言宏定义#define的理解与资料整理

    1. 利用define来定义 数值宏常量 #define 宏定义是个演技非常高超的替身演员,但也会经常耍大牌的,所以我们用它要慎之又慎.它可以出现在代码的任何地方,从本行宏定义开始,以后的代码就就都认 ...

  9. java boolean 值在内存中占几位?

      java boolean 值在内存中占几位?    <Java虚拟机规范>中这样描述:虽然定义了boolean这种数据类型,但是只对它提供了非常有限的支持.在Java虚拟机中没有任何供 ...

随机推荐

  1. AWS RDS 使用笔记

    创建VPC安全组 添加VPC子网 创建RDS子网组 创建RDS参数组 创建MySQL实例 查看RDS终端节点 使用 MySQL 监视器与数据库实例上的数据库连接 安装mysql client $ su ...

  2. samba服务器与远程登录ssh

    作者:相思羽  出处:http://www.cnblogs.com/xiang-siyu 欢迎转载,也请保留这段声明.谢谢! deepin安装与配置samba服务器 安装  apt-get insta ...

  3. 清除Eclipse和Myeclipse中的工作空间目录

    打开Eclipse或者Myeclipse后,选择功能菜单里的Windows->Preferences->, 弹出对话框后,选择General->Startup and Shutdow ...

  4. java 用eclipse j2ee写的servlet 程序,WEB-INF下的配置文件web.xml在哪啊?谢谢!

    我用的版本是tomcat7.0,在webcontent\web-inf里只有一个空文件夹lib,写完servlet 类程序,就可以运行了,我想知道自动生成的配置文件在哪里?或者说从哪里能够看出来配置内 ...

  5. WPF 皮肤之MathApps.Metro UI库

    在WPF中要想使用Metro风格是很简单的,可以自己画嘛.. 但是为了节省时间,哈,今天给大家推荐一款国外Metro风格的控件库. 本文只起到抛砖引玉的作用,有兴趣还是推荐大家上官网,Thanks,官 ...

  6. 什么情况下会调用到session_destroy()

    https://segmentfault.com/q/1010000000191102 首先 ... session_destory() 是一个函数 ... 这个函数在任何情况下都不会被 php 引擎 ...

  7. Oracle 11g之创建和管理表练习

    创建表: SQL> create table name (empno number(4), ename VARCHAR2(10)); 查看表结构: desc name; SQL> desc ...

  8. 类库探源——System.Drawing

    一.System.Drawing 命名空间简述 System.Drawing 命名空间提供访问 GDI+ 的基本功能,更高级的功能在 System.Drawing.Drawing2D,System.D ...

  9. 插入排序之python实现源码

    def insert_sort(old): for i in range(1, len(old)): for j in range(i, 0, -1): if(old[j] < old[j-1] ...

  10. (转)Objective-C中的instancetype和id区别

    有一个相同两个不同.相同 Written by Mattt Thompson on Dec 10th, Objective-C is a rapidly evolving language, in a ...