Use Compatibility Macros for Keil and SDCC
masterFwLib_STC8 provides a set of macros to ensure code compatibility between Keil C51 and SDCC. To write portable code, use these macros instead of compiler-specific keywords.
Key macros include:
- Memory space qualifiers:
__BIT,__DATA,__IDATA,__PDATA,__XDATA,__CODE. - Register access:
SBIT(name, addr, bit),SFR(name, addr),SFRX(addr),SFR16X(addr). - Interrupts:
INTERRUPT(name, vector),INTERRUPT_USING(name, vector, regnum). - Assembly:
NOP().
Detailed definitions can be found in include/fw_reg_base.h.
|
| ----------- | ---------------- | ---------------- |
| __BIT | bit | __bit |
| __DATA | data | __data |
| __IDATA | idata | __idata |
| __PDATA | pdata | __pdata |
| __XDATA | xdata | __xdata |
| __CODE | code | __code |
| SBIT(name, addr, bit) | sbit name = addr^bit | __sbit __at(addr+bit) name |
| SFR(name, addr) | sfr name = addr | __sfr __at(addr) name |
| SFRX(addr) | (*(unsigned char volatile xdata *)(addr)) | (*(unsigned char volatile __xdata *)(addr)) |
| SFR16X(addr) | (*(unsigned int volatile xdata *)(addr)) | (*(unsigned int volatile __xdata *)(addr)) |
| INTERRUPT(name, vector) | void name (void) interrupt vector | void name (void) __interrupt (vector) |
| INTERRUPT_USING(name, vector, regnum) | void name (void) interrupt vector using regnum | void name (void) __interrupt (vector) __using (regnum) |
| NOP() | _nop_() | __asm NOP __endasm |
|