|
- #ifndef _C51_BASE_DEF_H_
- #define _C51_BASE_DEF_H_
- #include
- #define TRUE 1
- #define FALSE 0
- typedef unsigned char BYTE;
- typedef unsigned int WORD;
- typedef unsigned long DWORD;
- typedef float FLOAT;
- typedef char CHAR;
- typedef unsigned char UCHAR;
- typedef int INT;
- typedef unsigned int UINT;
- typedef unsigned long ULONG;
- typedef UINT WPARAM;
- typedef UINT LPARAM;
- typedef UINT LRESULT;
- typedef void VOID;
- typedef const CONST;
- typedef void *PVOID;
- typedef void *LPVOID;
- typedef const UCHAR* LPCSTR;
- typedef bit BOOL;
- #define MAKEWORD(lo, hi) ((WORD)(((BYTE)(lo)) | ((WORD)((BYTE)(hi))) << 8))
- #define MAKEDWORD(lo, hi) ((DWORD)(((WORD)(lo)) | ((DWORD)((WORD)(hi))) << 16))
- #define LOWORD(l) ((WORD)(l))
- #define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
- #define LOBYTE(w) ((BYTE)(w))
- #define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
- #define MAX(a, b) (((a) > (b)) ? (a) : (b))
- #define MIN(a, b) (((a) < (b)) ? (a) : (b))
- #define SET_STATE_FLAG(state, mask) ((state) |= (mask))
- #define RESET_STATE_FLAG(state, mask) ((state) &= ~(mask))
- #define TEST_STATE_FLAG(state, mask) (((state) & (mask)) != 0) //需要保证是逻辑结果
- #define TEST_BIT(b, offset) (1 & ((b) >> (offset)))
- #define SET_BIT(b, offset) ((b) |= (1 << (offset)))
- #define RESET_BIT(b, offset) ((b) &= (~(1 << (offset))))
- #define ELEMENT_NUM(array) (sizeof(array) / sizeof(array[0]))
- //将BCD码变为十进制,如将0x23变为23
- //注意:高四位和低四位均不能大于9
- #define BCD_TO_DECIMAL(bcd) ((BYTE)((((BYTE)(bcd)) >> 4) * 10 + (((BYTE)(bcd)) & 0x0f)))
- #define DECIMAL_TO_BCD(decimal) ((BYTE)(((((BYTE)(decimal)) / 10) << 4) | ((BYTE)(decimal)) % 10))
- #define NOP() _nop_()
- #define BYTE_ROTATE_LEFT(b, n) _crol_(b, n)
- #define BYTE_ROTATE_RIGHT(b, n) _cror_(b, n)
- #define WORD_ROTATE_LEFT(w, n) _irol_(w, n)
- #define WORD_ROTATE_RIGHT(w, n) _iror_(w, n)
- #define DWORD_ROTATE_LEFT(dw, n) _lrol_(dw, n)
- #define DWORD_ROTATE_RIGHT(dw, n) _lror_(dw, n)
- #define ENABLE_ALL_INTERRUPTS() (EA = 1)
- #define DISABLE_ALL_INTERRUPTS() (EA = 0)
- #endif
复制代码 |
|