📄 compiler.h
字号:
#define OUT_X(addrx,value) (*addrx = value)
#define IN_X(addrx) (*addrx)
# define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b
# define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b
// Align on the upper value <val> on a <n> boundary
// i.e. Upper(0, 4)= 4
// Upper(1, 4)= 4
// Upper(2, 4)= 4
// Upper(3, 4)= 4
// Upper(4, 4)= 8
// ../..
# define Upper(val, n) ( ((val)+(n)) & ~((n)-1) )
// Align up <val> on a <n> boundary
// i.e. Align_up(0, 4)= 0
// Align_up(1, 4)= 4
// Align_up(2, 4)= 4
// Align_up(3, 4)= 4
// Align_up(4, 4)= 4
// ../..
# define Align_up(val, n) ( ((val)+(n)-1) & ~((n)-1) )
// Align down <val> on a <n> boundary
// i.e. Align_down(0, 4)= 0
// Align_down(1, 4)= 0
// Align_down(2, 4)= 0
// Align_down(3, 4)= 0
// Align_down(4, 4)= 4
// ../..
# define Align_down(val, n) ( (val) & ~((n)-1) )
/*M**************************************************************************
* NAME: Long_call
*----------------------------------------------------------------------------
* PARAMS:
* addr: address of the routine to call
*----------------------------------------------------------------------------
* PURPOSE:
* Call the routine at address addr: generate an Assembly LCALL addr opcode.
*----------------------------------------------------------------------------
* EXAMPLE:
* Long_call(0); // Software reset (if no IT used before)
*----------------------------------------------------------------------------
* NOTE:
* May be used as a long jump opcode in some special cases
*****************************************************************************/
#define Long_call(addr) ((*(void (_ConstType_*)(void))(addr))())
/* {For Langdoc} */
/***********************************************************
SET_SFR_BIT macro
parameters
sfr_reg : defined value in include file for sfr register
bit_pos : defined value B_XX in include file for particular
bit of sfr register
bit_val : CLR / SET
************************************************************/
#define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
/***********************************************************
bit_is_clear macro
parameters
PORT : defined value in include file for sfr register
POSITION : defined value in include file for particular
bit of sfr register
example : if (bit_is_clear(PORTB,PORTB3)) ...
************************************************************/
#define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
/***********************************************************
bit_is_set macro
parameters
PORT : defined value in include file for sfr register
POSITION : defined value in include file for particular
bit of sfr register
example : if (bit_is_set(PORTB,PORTB3)) ...
************************************************************/
#define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
/******************************************************************************/
/* IAR COMPILER */
/******************************************************************************/
#define __IOMACRO_H
#define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
/*----------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ASM__
/*----------------------------------------------------------------------------*/
/* Byte sized SFRs */
#define SFR_B_BITS(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
sfrb _NAME = _ADDR
#define SFR_B_BITS_EXT(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
sfrb _NAME = _ADDR
#define SFR_B2_BITS(_NAME1,_NAME2,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
ASMSFRB2 _NAME1, _NAME2, _ADDR
ASMSFRB2 MACRO
sfrb \1 = \3
sfrb \2 = \3
ENDM
/* Word sized SFRs, needs to be expanded into an assembler macro first. */
#define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
ASMSFRW _NAME, _ADDR
#define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
ASMSFRW _NAME, _ADDR
ASMSFRW MACRO
sfrw \1 = \2
sfrb \1L = (\2+0)
sfrb \1H = (\2+1)
ENDM
#endif /* __IAR_SYSTEMS_ASM__ */
/*----------------------------------------------------------------------------*/
#ifdef __ICCAVR__
/*----------------------------------------------------------------------------*/
#define __BYTEBITS(_NAME,_A,_B,_C,_D,_E,_F,_G,_H) \
unsigned char _NAME ## _ ## _A:1, \
_NAME ## _ ## _B:1, \
_NAME ## _ ## _C:1, \
_NAME ## _ ## _D:1, \
_NAME ## _ ## _E:1, \
_NAME ## _ ## _F:1, \
_NAME ## _ ## _G:1, \
_NAME ## _ ## _H:1;
#define SFR_B_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
__io union { \
unsigned char _NAME; /* The sfrb as 1 byte */ \
struct { /* The sfrb as 8 bits */ \
__BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
}; \
} @ _ADDR;
#define SFR_B2_BITS(_NAME1, _NAME2, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
__io union { \
unsigned char _NAME1; /* The sfrb as 1 byte */ \
unsigned char _NAME2; /* The sfrb as 1 byte */ \
struct { /* The sfrb as 8 bits */ \
__BYTEBITS(_NAME1, _A,_B,_C,_D,_E,_F,_G,_H) \
}; \
struct { /* The sfrb as 8 bits */ \
__BYTEBITS(_NAME2, _A,_B,_C,_D,_E,_F,_G,_H) \
}; \
} @ _ADDR;
#define SFR_B_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
__tiny __no_init volatile union { \
unsigned char _NAME; /* The sfrb as 1 byte */ \
struct { /* The sfrb as 8 bits */ \
__BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
}; \
} @ _ADDR;
#define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
__io union { \
unsigned short _NAME; /* The sfrw as 1 short */ \
struct { /* The sfrw as 16 bits */ \
__BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) /* Bit names defined by user */ \
__BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P) /* Bit names defined by user */ \
}; \
struct { /* The sfrw as 2 bytes */ \
unsigned char _NAME ## L; \
unsigned char _NAME ## H; \
}; \
struct { /* The sfrw as 2 x 8 bits */ \
__BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) /* Bit names hard coded to 0-7 */ \
__BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) /* Bit names hard coded to 0-7 */ \
}; \
} @ _ADDR;
#define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
__io union { \
unsigned short _NAME; \
struct { /* The sfrw_ext as 16 bits */ \
__BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) /* Bit names defined by user */ \
__BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P) /* Bit names defined by user */ \
}; \
struct { /* The sfrw _ext as 2 bytes */ \
unsigned char _NAME ## L; \
unsigned char _NAME ## H; \
}; \
struct { /* The sfrw_ext as 2 x 8 bits */ \
__BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) /* Bit names hard coded to 0-7 */ \
__BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) /* Bit names hard coded to 0-7 */ \
}; \
} @ _ADDR;
#endif
#define SFR_B(_NAME, _ADDR) SFR_B_BITS(_NAME, _ADDR, \
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
#define SFR_B2(_NAME1, _NAME2, _ADDR) SFR_B2_BITS(_NAME1, _NAME2, _ADDR, \
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
#define SFR_B_EXT(_NAME, _ADDR) SFR_B_BITS_EXT(_NAME, _ADDR, \
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
#define SFR_W(_NAME, _ADDR) SFR_W_BITS(_NAME, _ADDR, \
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7, \
Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
#define SFR_W_EXT(_NAME, _ADDR) SFR_W_BITS_EXT(_NAME, _ADDR, \
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7, \
Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
/******************************************************************************/
/* GCC COMPILER */
/******************************************************************************/
#ifdef AVRGCC
#define _CONST_TYPE_
#define _ConstType_ __flash
#define _MemType_
#define _GenericType_ __generic
#define code PROGMEM
#define xdata
#define idata
#define data
#define At(x) @ x
#define pdata
#define bdata
#define bit U8
#define bool U8
//#include <avr/sfr_defs.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define Enable_interrupt() sei()
#define Disable_interrupt() cli()
#endif
#endif /* _COMPILER_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -