typedef struct bit0 : 1
这句话定义了一个位域,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的更多相关文章
- [转载]彻底弄清struct和typedef struct
struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int ...
- struct和typedef struct彻底明白了
struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int ...
- [C语言]关于struct和typedef struct
在C中定义一个结构体类型要用typedef: *************************************************************************** t ...
- struct和typedef struct用法
参考:http://www.cnblogs.com/qyaizs/articles/2039101.html C语言: typedef struct Student{ int score; }Stu; ...
- struct和typedef struct
转自:http://www.cnblogs.com/qyaizs/articles/2039101.html struct和typedef struct 分三块来讲述: 1 首先://注意在C和C++ ...
- typedef struct 结构体
typedef struct _TTTT_ { int i; }TT_TT; 定义变量如下: struct _TTTT_ NewTT;方法1 TT_TT NewTT;方法2 是声明和定义 ...
- C语言中的struct和typedef struct<转载>
原文:http://www.nowamagic.net/librarys/veda/detail/1785 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数 ...
- C/C++语法知识:typedef struct 用法详解
第一篇:typedef struct与struct的区别 1. 基本解释 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数据类型(int,char等)和自定 ...
- struct和typedef struct的区别
当typedef与结构结合使用时,会有一些比较复杂的情况,而且在C语言和C++里面有略有差别,因此从网上摘录了一些资料. 1 首先: 在C中定义一个结构体类型要用typedef: ...
随机推荐
- JavaWeb基础—MVC与三层架构
一.MVC的概念 MVC模式(Model–view–controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller ...
- PostgreSQL集群方案相关索引页
磨砺技术珠矶,践行数据之道,追求卓越价值 返回顶级页:PostgreSQL索引页 本页记录所有本人所写的PostgreSQL的集群方案相关文摘和文章的链接: pgpool-II: 1 pgpool-I ...
- [BZOJ3745][COCI2015]Norma[分治]
题意 题目链接 分析 考虑分治,记当前分治区间为 \(l,r\) . 枚举左端点,然后发现右端点无非三种情况: 极大极小值都在左边; 有一个在左边; 极大极小值都在右边; 考虑递推 \(l\) 的同时 ...
- yum 执行不了, 解决方法
在执行yum命令时忽然发现出现以下报错: 1 2 3 4 5 # yum list File "/usr/bin/yum", line 30 except KeyboardInte ...
- C++构造函数和析构函数什么情况下会用
析构函数: 1. 对象生命周期结束,被销毁时: 2. delete 指向对象的指针时: 3. delete 指向基类对象的指针时,其析构函数是虚函数: 4. 在嵌套关系中,对象A是对象B的成员,当对象 ...
- NAT概念解释(不完全版,但不会搞错...)
NAT在计算器网络中,网络地址转换(Network Address Translation,缩写为NAT),也叫做网络掩蔽或者IP掩蔽(IP masquerading)是一种IP数据包在通过路由器或防 ...
- 求二维数组最大子数组的和。郭林林&胡潇丹
求二维数组子数组的最大值,开始思路不太清晰.先从最简单的开始. 以2*2的简单数组为例找规律, 假设最大数为a[0][0],则summax=a[0][0],比较a[0][0]+a[0][1].a[0] ...
- CentOS查看一共安装了多少软件包,是那些软件包
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/48292853 一.如何得知共安装了多少个软件包 [root@localhost ~ ...
- 你也可以手绘二维码(二)纠错码字算法:数论基础及伽罗瓦域GF(2^8)
摘要:本文讲解二维码纠错码字生成使用到的数学数论基础知识,伽罗瓦域(Galois Field)GF(2^8),这是手绘二维码填格子理论基础,不想深究可以直接跳过.同时数论基础也是 Hash 算法,RS ...
- Spark Streaming流式处理
Spark Streaming介绍 Spark Streaming概述 Spark Streaming makes it easy to build scalable fault-tolerant s ...