// 开关
#define SW_ON 1
#define SW_OFF 2
#define SW_INVERT 3
// 右移位替代除法
#define SHIFT_DIVISOR_2 1 // 右移1位 (除以2)
#define SHIFT_DIVISOR_4 2 // 右移2位 (除以4)
#define SHIFT_DIVISOR_8 3 // 右移3位 (除以8)
#define SHIFT_DIVISOR_16 4 // 右移4位 (除以16)
#define SHIFT_DIVISOR_32 5 // 右移5位 (除以32)
#define SHIFT_DIVISOR_64 6 // 右移6位 (除以64)
#define SHIFT_DIVISOR_128 7 // 右移7位 (除以128)
#define SHIFT_DIVISOR_256 8 // 右移8位 (除以256)
// ------------------------------------------------------
#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)) )
#define GetBit8B(Byte, Bit) (((Byte) & (((uint64_t)1)<<(Bit))) ? 1 : 0)
// ===多二进制位操作宏===
#define SetBits(Byte, Bits) ( (Byte) |= (Bits) )
#define ClrBits(Byte, Bits) ( (Byte) &= ~(Bits) )
#define ComBits(Byte, Bits) ( (Byte) ^= (Bits) )
#define GetBits(Byte, Bits) ( (Byte) & (Bits) )
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !