// ------------------------------------------------------
#ifndef __I
#ifdef __cplusplus
#define __I volatile // 只读
#else
// 程序空间在数据空间中可见(可使用const变量)
#define __I volatile const // 只读
#endif
#endif
#ifndef __O
#define __O volatile // 只写
#endif
#ifndef __IO
#define __IO volatile // 读写
#endif
typedef unsigned char uint8_t, INT8U, BYTE;
typedef signed char int8_t, INT8S;
typedef unsigned int uint16_t, INT16U, HWORD;
typedef signed int int16_t, INT16S;
typedef unsigned long int uint32_t, INT32U, WORD;
typedef signed long int int32_t, INT32S;
typedef unsigned long long int uint64_t, INT64U, DWORD;
typedef signed long long int int64_t, INT64S;
#define UINT8_MAX (uint8_t)( 255)
#define INT8_MIN (int8_t)( -128)
#define INT8_MAX (int8_t)( 127)
#define UINT14_MAX (uint16_t)(16383)
#define INT14_MAX (int16_t)( 16383)
#define UINT16_MAX (uint16_t)(65535)
#define INT16_MIN (int16_t)(-32768)
#define INT16_MAX (int16_t)( 32767)
#define UINT32_MAX (uint32_t)(4294967295)
#define INT32_MIN (int32_t)(-2147483648)
#define INT32_MAX (int32_t)( 2147483647)
#define UINT64_MAX (uint64_t)(18446744073709551615)
#define INT64_MIN (int64_t)(-9223372036854775808)
#define INT64_MAX (int64_t)( 9223372036854775807)
// ------------------------------------------------
// 字节操作类型
typedef union
{
__IO char ch; // 字符
__IO int8_t iByte; // 有符号数
__IO uint8_t byte; // 字节
struct
{
__IO uint8_t d0:4;
__IO uint8_t d1:4;
} hByte; // 半字节
struct
{
__IO uint8_t d0:1;
__IO uint8_t d1:1;
__IO uint8_t d2:1;
__IO uint8_t d3:1;
__IO uint8_t d4:1;
__IO uint8_t d5:1;
__IO uint8_t d6:1;
__IO uint8_t d7:1;
} bittel; // 二进制位
} Byte_t, *Byte_pt;
// 半字操作类型(存储模式:小端模式,低字节在低地址)
typedef union
{
__IO int16_t iHWord; // 有符号数
__IO uint16_t hWord; // 半字
struct
{
__IO uint8_t d0;
__IO uint8_t d1;
} byte; // 字节
struct
{
__IO uint8_t d0:4;
__IO uint8_t d1:4;
__IO uint8_t d2:4;
__IO uint8_t d3:4;
} hByte; // 半字节
struct
{
__IO uint8_t d0:1;
__IO uint8_t d1:1;
__IO uint8_t d2:1;
__IO uint8_t d3:1;
__IO uint8_t d4:1;
__IO uint8_t d5:1;
__IO uint8_t d6:1;
__IO uint8_t d7:1;
__IO uint8_t d8:1;
__IO uint8_t d9:1;
__IO uint8_t d10:1;
__IO uint8_t d11:1;
__IO uint8_t d12:1;
__IO uint8_t d13:1;
__IO uint8_t d14:1;
__IO uint8_t d15:1;
} bittel; // 二进制位
} HWord_t, *HWord_pt;
// 字操作类型(存储模式:小端模式)
typedef union
{
__IO float fVal; // 单精度浮点数
__IO int32_t iWord; // 有符号数
__IO uint32_t word; // 字
struct
{
__IO uint16_t d0;
__IO uint16_t d1;
} hWord; // 半字
struct
{
__IO uint8_t d0;
__IO uint8_t d1;
__IO uint8_t d2;
__IO uint8_t d3;
} byte; // 字节
struct
{
__IO uint8_t d0:4;
__IO uint8_t d1:4;
__IO uint8_t d2:4;
__IO uint8_t d3:4;
__IO uint8_t d4:4;
__IO uint8_t d5:4;
__IO uint8_t d6:4;
__IO uint8_t d7:4;
} hByte; // 半字节
struct
{
__IO uint8_t d0:1;
__IO uint8_t d1:1;
__IO uint8_t d2:1;
__IO uint8_t d3:1;
__IO uint8_t d4:1;
__IO uint8_t d5:1;
__IO uint8_t d6:1;
__IO uint8_t d7:1;
__IO uint8_t d8:1;
__IO uint8_t d9:1;
__IO uint8_t d10:1;
__IO uint8_t d11:1;
__IO uint8_t d12:1;
__IO uint8_t d13:1;
__IO uint8_t d14:1;
__IO uint8_t d15:1;
__IO uint8_t d16:1;
__IO uint8_t d17:1;
__IO uint8_t d18:1;
__IO uint8_t d19:1;
__IO uint8_t d20:1;
__IO uint8_t d21:1;
__IO uint8_t d22:1;
__IO uint8_t d23:1;
__IO uint8_t d24:1;
__IO uint8_t d25:1;
__IO uint8_t d26:1;
__IO uint8_t d27:1;
__IO uint8_t d28:1;
__IO uint8_t d29:1;
__IO uint8_t d30:1;
__IO uint8_t d31:1;
} bittel; // 二进制位
} Word_t, *Word_pt;
// 双字操作类型(存储模式:小端模式)
typedef union
{
__IO double dFVal; // 双精度浮点数
__IO int64_t iDWord; // 有符号数
__IO uint64_t dWord; // 双字
struct
{
__IO uint32_t d0;
__IO uint32_t d1;
} word; // 字
struct
{
__IO uint16_t d0;
__IO uint16_t d1;
__IO uint16_t d2;
__IO uint16_t d3;
} hWord; // 半字
struct
{
__IO uint8_t d0;
__IO uint8_t d1;
__IO uint8_t d2;
__IO uint8_t d3;
__IO uint8_t d4;
__IO uint8_t d5;
__IO uint8_t d6;
__IO uint8_t d7;
} byte; // 字节
struct
{
__IO uint8_t d0:4;
__IO uint8_t d1:4;
__IO uint8_t d2:4;
__IO uint8_t d3:4;
__IO uint8_t d4:4;
__IO uint8_t d5:4;
__IO uint8_t d6:4;
__IO uint8_t d7:4;
__IO uint8_t d8:4;
__IO uint8_t d9:4;
__IO uint8_t d10:4;
__IO uint8_t d11:4;
__IO uint8_t d12:4;
__IO uint8_t d13:4;
__IO uint8_t d14:4;
__IO uint8_t d15:4;
} hByte; // 半字节
struct
{
__IO uint8_t d0:1;
__IO uint8_t d1:1;
__IO uint8_t d2:1;
__IO uint8_t d3:1;
__IO uint8_t d4:1;
__IO uint8_t d5:1;
__IO uint8_t d6:1;
__IO uint8_t d7:1;
__IO uint8_t d8:1;
__IO uint8_t d9:1;
__IO uint8_t d10:1;
__IO uint8_t d11:1;
__IO uint8_t d12:1;
__IO uint8_t d13:1;
__IO uint8_t d14:1;
__IO uint8_t d15:1;
__IO uint8_t d16:1;
__IO uint8_t d17:1;
__IO uint8_t d18:1;
__IO uint8_t d19:1;
__IO uint8_t d20:1;
__IO uint8_t d21:1;
__IO uint8_t d22:1;
__IO uint8_t d23:1;
__IO uint8_t d24:1;
__IO uint8_t d25:1;
__IO uint8_t d26:1;
__IO uint8_t d27:1;
__IO uint8_t d28:1;
__IO uint8_t d29:1;
__IO uint8_t d30:1;
__IO uint8_t d31:1;
__IO uint8_t d32:1;
__IO uint8_t d33:1;
__IO uint8_t d34:1;
__IO uint8_t d35:1;
__IO uint8_t d36:1;
__IO uint8_t d37:1;
__IO uint8_t d38:1;
__IO uint8_t d39:1;
__IO uint8_t d40:1;
__IO uint8_t d41:1;
__IO uint8_t d42:1;
__IO uint8_t d43:1;
__IO uint8_t d44:1;
__IO uint8_t d45:1;
__IO uint8_t d46:1;
__IO uint8_t d47:1;
__IO uint8_t d48:1;
__IO uint8_t d49:1;
__IO uint8_t d50:1;
__IO uint8_t d51:1;
__IO uint8_t d52:1;
__IO uint8_t d53:1;
__IO uint8_t d54:1;
__IO uint8_t d55:1;
__IO uint8_t d56:1;
__IO uint8_t d57:1;
__IO uint8_t d58:1;
__IO uint8_t d59:1;
__IO uint8_t d60:1;
__IO uint8_t d61:1;
__IO uint8_t d62:1;
__IO uint8_t d63:1;
} bittel; // 二进制位
} DWord_t, *DWord_pt;
// ------------------------------------------------------
// 时间计算
typedef struct CalTime
{
__IO uint16_t bDelay:1; // 延时标识
__IO uint16_t bExe:1; // 执行标识
__IO uint16_t bCon:1; // 控制标识
__IO uint16_t con:13; // 控制值 [0,8191]
__IO uint16_t val; // 计数值
} CalTime_t, *CalTime_pt;
// ------------------------------------------------------
// ===单二进制位操作宏===
// 2字节长度
#define SetBit2B(Byte, Bit) ( (Byte) |= (((uint16_t)1)<<(Bit)) )
#define ClrBit2B(Byte, Bit) ( (Byte) &= ~(((uint16_t)1)<<(Bit)) )
#define ComBit2B(Byte, Bit) ( (Byte) ^= (((uint16_t)1)<<(Bit)) )
#define GetBit2B(Byte, Bit) (((Byte) & (((uint16_t)1)<<(Bit))) ? 1 : 0)
// 4字节长度
#define SetBit4B(Byte, Bit) ( (Byte) |= (((uint32_t)1)<<(Bit)) )
#define ClrBit4B(Byte, Bit) ( (Byte) &= ~(((uint32_t)1)<<(Bit)) )
#define ComBit4B(Byte, Bit) ( (Byte) ^= (((uint32_t)1)<<(Bit)) )
#define GetBit4B(Byte, Bit) (((Byte) & (((uint32_t)1)<<(Bit))) ? 1 : 0)
// 8字节长度
#define SetBit8B(Byte, Bit) ( (Byte) |= (((uint64_t)1)<<(Bit)) )
#define ClrBit8B(Byte, Bit) ( (Byte) &= ~(((uint64_t)1)<<(Bit)) )
#define ComBit8B(Byte, Bit) ( (Byte) ^= (((uint64_t)1)<<(Bit)) )
版权说明:本资料由用户提供并上传,仅用于学习交流;若内容存在侵权,请进行举报,或 联系我们 删除。
汉高
2025-03-21
Tokyo Electron
2025-03-04
相关评论
(下载后评价送E币 我要评论)
没有更多评论了