📄 my_bit.h
字号:
# ifndef _MY_BIT_H_
# define _MY_BIT_H_
/*****************************************************************
* 声明库名称:位段数据类型声明库 *
* 版本: v0.01 *
* 作者: I ROBOT *
* 创建日期: Copyright (C) 2008年10月14日 *
*----------------------------------------------------------------*
* [支持库] *
* 支持库名称:AVR_Chip_Configure.h(AVR芯片配置头文件) *
* 支持库版本:v0.01 *
* 支持库说明:AVR芯片配置,可以选择不同的ATMEGA芯片 *
*----------------------------------------------------------------*
* [版本更新] *
* 更新: I ROBOT *
* 更新日期: *
* 版本: *
*----------------------------------------------------------------*
* [版本历史] *
* v0.01 创建版本,创建了位段数据类型 *
*----------------------------------------------------------------*
* [使用说明] *
* 1.该库文件属于基础库文件 *
*****************************************************************/
/********************
* 头 文 件 配 置 区 *
********************/
#include "AVR_Chip_Configure.h"
/********************
* 系 统 宏 定 义 *
********************/
# define SET_BIT8_FORMAT(VAR) (*((volatile BYTE_DIV_8_BIT *)&VAR))
# define SET_BYTE_DIV_2(VAR) (*((volatile BYTE_DIV_2 *)&VAR))
# define SET_BIT16_FORMAT(VAR) (*((volatile BYTE_DIV_16_BIT *)&VAR))
# define SET_WORD_DIV_2(VAR) (*((volatile WORD_DIV_2 *)&VAR))
# define SET_WORD_DIV_4(VAR) (*((volatile WORD_DIV_4 *)&VAR))
# define SET_BIT32_FORMAT(VAR) (*((volatile BYTE_DIV_32_BIT *)&VAR))
# define SET_DWORD_DIV_2(VAR) (*((volatile DWORD_DIV_2 *)&VAR))
# define SET_DWORD_DIV_4(VAR) (*((volatile DWORD_DIV_4 *)&VAR))
# define SET_DWORD_DIV_8(VAR) (*((volatile DWORD_DIV_8 *)&VAR))
/********************
* BYTE 8 位 段 *
********************/
typedef struct BYTE_8BIT
{
unsigned BIT0:1;
unsigned BIT1:1;
unsigned BIT2:1;
unsigned BIT3:1;
unsigned BIT4:1;
unsigned BIT5:1;
unsigned BIT6:1;
unsigned BIT7:1;
}BYTE_DIV_8_BIT;
/********************
* WORD 16 位 段 *
********************/
typedef struct BYTE_16BIT
{
unsigned BIT0:1;
unsigned BIT1:1;
unsigned BIT2:1;
unsigned BIT3:1;
unsigned BIT4:1;
unsigned BIT5:1;
unsigned BIT6:1;
unsigned BIT7:1;
unsigned BIT8:1;
unsigned BIT9:1;
unsigned BIT10:1;
unsigned BIT11:1;
unsigned BIT12:1;
unsigned BIT13:1;
unsigned BIT14:1;
unsigned BIT15:1;
}BYTE_DIV_16_BIT;
/********************
* DWORD 32 位 段 *
********************/
typedef struct BYTE_32BIT
{
unsigned BIT0:1;
unsigned BIT1:1;
unsigned BIT2:1;
unsigned BIT3:1;
unsigned BIT4:1;
unsigned BIT5:1;
unsigned BIT6:1;
unsigned BIT7:1;
unsigned BIT8:1;
unsigned BIT9:1;
unsigned BIT10:1;
unsigned BIT11:1;
unsigned BIT12:1;
unsigned BIT13:1;
unsigned BIT14:1;
unsigned BIT15:1;
unsigned BIT16:1;
unsigned BIT17:1;
unsigned BIT18:1;
unsigned BIT19:1;
unsigned BIT20:1;
unsigned BIT21:1;
unsigned BIT22:1;
unsigned BIT23:1;
unsigned BIT24:1;
unsigned BIT25:1;
unsigned BIT26:1;
unsigned BIT27:1;
unsigned BIT28:1;
unsigned BIT29:1;
unsigned BIT30:1;
unsigned BIT31:1;
}BYTE_DIV_32_BIT;
/********************
* BYTE 2 分 量 *
********************/
typedef struct BYTE_DIV_2_FOURBIT
{
unsigned BYTE_L:4;
unsigned BYTE_H:4;
}BYTE_DIV_2;
/********************
* WORD 2 分 量 *
********************/
typedef struct WORD_DIV_2_BYTE
{
unsigned BYTEA:8;
unsigned BYTEB:8;
}WORD_DIV_2;
/********************
* WORD 4 位 分 量 *
********************/
typedef struct WORD_DIV_4_FOURBIT
{
unsigned BYTEA_L:4;
unsigned BYTEA_H:4;
unsigned BYTEB_L:4;
unsigned BYTEB_H:4;
}WORD_DIV_4;
/********************
* DWORD 2 分 量 *
********************/
typedef struct DWORD_DIV_2_WORD
{
unsigned WORDA:16;
unsigned WORDB:16;
}DWORD_DIV_2;
/********************
* DWORD 4 分 量 *
********************/
typedef struct DWORD_DIV_4_BYTE
{
unsigned BYTEA:8;
unsigned BYTEB:8;
unsigned BYTEC:8;
unsigned BYTED:8;
}DWORD_DIV_4;
/********************
* DWORD 8 分 量 *
********************/
typedef struct DWORD_DIV_8_FOURBIT
{
unsigned BYTEA_L:4;
unsigned BYTEA_H:4;
unsigned BYTEB_L:4;
unsigned BYTEB_H:4;
unsigned BYTEC_L:4;
unsigned BYTEC_H:4;
unsigned BYTED_L:4;
unsigned BYTED_H:4;
}DWORD_DIV_8;
/********************
* 常 数 宏 定 义 *
********************/
/********************
* 动 作 宏 定 义 *
********************/
/********************
* 模块结构体定义区 *
********************/
/********************
* 函 数 声 明 区 *
********************/
/********************
* 模块函数声明区 *
********************/
/********************
* 模块变量声明区 *
********************/
/********************
* 全局变量声明区 *
********************/
# endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -