这句话定义了一个位域,bit0是该位域的域名,而且bit0只占用一个位。
位域是指信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位。为了节省存储空间,并使处理简便,C语言提供了一种数据结构,称为“位域”或“位段”。所谓“位域”是把一个字节中的二进位划分为几个不同的区域, 并说明每个区域的位数。每个域有一个域名,允许在程序中按域名进行操作。 这样就可以把几个不同的对象用一个字节的二进制位域来表示。

#define Uint unsigned int
typedef struct
{
Uint bit0 : 1;
Uint bit1 : 1;
Uint bit2 : 1;
Uint bit3 : 1;
Uint bit4 : 1;
Uint bit5 : 1;
Uint bit6 : 1;
Uint bit7 : 1;
Uint bit8 : 1;
Uint bit9 : 1;
Uint bit10 : 1;
Uint bit11 : 1;
Uint bit12 : 1;
Uint bit13 : 1;
Uint bit14 : 1;
Uint bit15 : 1;
}Bit; typedef struct
{
Uint bytel : 8;
Uint byteh : 8;
}Byte; typedef union
{
Bit bit;
Byte byte;
Uint port;
}UNport; #define PA ((volatile UNport *)(0x7000))
#define PA_Buffer ((volatile UNport *)(0x7001))
#define PA_Dir ((volatile UNport *)(0x7002))
#define PA_Attrib ((volatile UNport *)(0x7003))
#define PA_Latch ((volatile UNport *)(0x7004))
#define PB ((volatile UNport *)(0x7005))
#define PB_Buffer ((volatile UNport *)(0x7006))
#define PB_Dir ((volatile UNport *)(0x7007))
#define PB_Attrib ((volatile UNport *)(0x7008))
#define Poscu ((volatile UNport *)(0x7013))
#define Ptbu ((volatile UNport *)(0x700e))
#define Ptbc ((volatile UNport *)(0x700f))
#define Pt0 ((volatile UNport *)(0x700a))
#define Pt1 ((volatile UNport *)(0x700c))
#define Pt0u ((volatile UNport *)(0x700b))
#define Pt1u ((volatile UNport *)(0x700d))
#define Pintu ((volatile UNport *)(0x7010))
#define Pintc ((volatile UNport *)(0x7011))
#define Padm ((volatile UNport *)(0x7014))
#define Padl ((volatile UNport *)(0x702c))
#define Padu ((volatile UNport *)(0x7015))
#define Padmuxu ((volatile UNport *)(0x702b))
#define Pda0 ((volatile UNport *)(0x7017))
#define Pda1 ((volatile UNport *)(0x7016))
#define Pdau ((volatile UNport *)(0x702a))
#define Pwdogc ((volatile UNport *)(0x7012))
#define Pflashu ((volatile UNport *)(0x7555)) //------------------------------------------------------------------------------------------------------- //以下部分在编程中直接调用使用; #define Watchdog_Clear Pwdogc->port #define P0_0 PA->bit.bit0
#define P0_1 PA->bit.bit1
#define P0_2 PA->bit.bit2
#define P0_3 PA->bit.bit3
#define P0_4 PA->bit.bit4
#define P0_5 PA->bit.bit5
这种结构体定义方式书上没有解释?不明白什么意思?Uint bit: 1;
: 1?没见过?为什么这样可以将凌阳单片机的接口进行位定义?

回答:

一.

typedef struct
{
Uint bit0 : 1;
Uint bit1 : 1;
Uint bit2 : 1;
Uint bit3 : 1;
Uint bit4 : 1;
Uint bit5 : 1;
Uint bit6 : 1;
Uint bit7 : 1;
Uint bit8 : 1;
Uint bit9 : 1;
Uint bit10 : 1;
Uint bit11 : 1;
Uint bit12 : 1;
Uint bit13 : 1;
Uint bit14 : 1;
Uint bit15 : 1;
}Bit;
这个结构体有16个单元,每个单元一位,正好可以用于单片机中的数据保存和读取问题.应该是16位机吧

二.

typedef struct
{
Uint bit0 : 1;
Uint bit1 : 1;
Uint bit2 : 1;
Uint bit3 : 1;
Uint bit4 : 1;
Uint bit5 : 1;
Uint bit6 : 1;
Uint bit7 : 1;
Uint bit8 : 1;
Uint bit9 : 1;
Uint bit10 : 1;
Uint bit11 : 1;
Uint bit12 : 1;
Uint bit13 : 1;
Uint bit14 : 1;
Uint bit15 : 1;
}Bit; 每个成员各自占1个bit,这是按bit位来定义结构体的
 
 

typedef struct bit0 : 1的更多相关文章

  1. [转载]彻底弄清struct和typedef struct

    struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int ...

  2. struct和typedef struct彻底明白了

    struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int ...

  3. [C语言]关于struct和typedef struct

    在C中定义一个结构体类型要用typedef: *************************************************************************** t ...

  4. struct和typedef struct用法

    参考:http://www.cnblogs.com/qyaizs/articles/2039101.html C语言: typedef struct Student{ int score; }Stu; ...

  5. struct和typedef struct

    转自:http://www.cnblogs.com/qyaizs/articles/2039101.html struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++ ...

  6. typedef struct 结构体

    typedef struct _TTTT_ {   int    i;  }TT_TT; 定义变量如下: struct _TTTT_  NewTT;方法1 TT_TT NewTT;方法2 是声明和定义 ...

  7. C语言中的struct和typedef struct<转载>

    原文:http://www.nowamagic.net/librarys/veda/detail/1785 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数 ...

  8. C/C++语法知识:typedef struct 用法详解

    第一篇:typedef struct与struct的区别 1. 基本解释 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数据类型(int,char等)和自定 ...

  9. struct和typedef struct的区别

    当typedef与结构结合使用时,会有一些比较复杂的情况,而且在C语言和C++里面有略有差别,因此从网上摘录了一些资料. 1 首先:      在C中定义一个结构体类型要用typedef:       ...

随机推荐

  1. GoLang 命令

    目录 查看可用命令 build 和 run 命令 go build编译时的附加参数 clent命令 fmt 和 doc 命令 get 命令 远程包的路径格式 go get+远程包 go get使用时的 ...

  2. Nodejs-第一篇(什么是NodeJS)

    NodeJS 介绍 Node.js 是什么? 1.Node.js 是一个开发平台,就像Java开发平台..Net开发平台.PHP开发平台.Apple开发平台一样: 什么是开发平台?它们有对应的编程语言 ...

  3. Firebird3 多文件支持

    默认建立数据库时为一个数据文件,但文件不能无限大,故可以为数据库增加新文件: isql 打开数据库,并conn到指定数据库,然后 Alter databaseAdd file ‘d:\data\d2. ...

  4. 批量分离SQL数据库语句

    --sp_helpdb--查看可用数据库 declare @name sysname, @sql nvarchar(4000) DECLARE roy CURSOR FOR --排除不分离的数据库名就 ...

  5. 人脸检测——MTCNN

    人脸检测——MTCNN .

  6. 标准输入输出 sys.stdin与sys.stdin

    1.python中的标准输入输出 如果需要更好的控制输出,而print不能满足需求,input也不能 sys.stdout,sys.stdin,sys.stderr就是你需要的. 2.输入:sys.s ...

  7. 【AHOI2006】基因匹配

    题面 题解 众所周知,最长公共子序列的$dp$是$\text{O}(n^2)$, 但是每一个数字只重复$5$遍,那么我们暴力匹配$25n$个点对 那么我们就可以将其变成求最长上升子序列 用二分栈或者树 ...

  8. Openstack入门篇(十六)之Cinder服务的部署与测试

    1.理解块存储服务 操作系统获得存储空间的方式一般有两种: 通过某种协议(SAS,SCSI,SAN,iSCSI 等)挂接裸硬盘,然后分区.格式化.创建文件系统:或者直接使用裸硬盘存储数据(数据库) 通 ...

  9. cogs2479 偏序 cdq+树套树

    cdq+树状数组套替罪羊树. cdq归并a,树套树解决b,c. 记住平衡树树根不能暴力清零!!! // It is made by XZZ #include<cstdio> #includ ...

  10. Flutter - > Android dependency 'com.android.support:support-v4' has different version for the compile (26.1.0) and runtime (27.1.1) classpath.

    Launching lib\main.dart on Nokia X6 in debug mode... Initializing gradle... Resolving dependencies.. ...