Compiler_defs.h is a header file provided by Silicon Labs which contains compiler-specific macro definitions which can be used in place of compiler-specific syntax to allow for code to be compiler independent. Each compiler uses different syntax for handling special function registers (SFRs), memory segments, and interrupt declarations. At compile-time, the compiler will replace every macro definition in the C source code with corresponding compilers-specific syntax found in compiler_defs.h. The compiler_defs.h file is organized by compiler using #defines to indicate blocks of macro definitions for each compiler. In the compiler_defs.h file, each supported compiler has a section which includes a #define statement for each macro definition, followed by a macro name with parameters and the corresponding compiler-specific syntax. Macro definitions can be easily modified or added to this file as needed.
Each compiler has its own way of declaring a bit in a bit addressable SFR. For example, if bit 5 in the SFR Port 1 was defined as ‘LED’, using compiler_defs.h it would look like this:
SBIT (LED,SFR_P1, 5); // Port 1 Pin 5
If the Raisonance compiler was used, that particular line of code would be replace with the following line of C code at compile time:
at (P1+5) sbit LED; // Port 1 Pin 5
If the Keil compiler was used, that particular line of code would be replace with the following line of C code at compile time:
sbit LED = P1^5; // Port 1 Pin 5
Compiler_defs.h allows one line of code to work between many compilers. Currently, the compiler_defs.h file contains macro definitions for:
NOP instructions
Common data containers
Unions
LSB and MSB defines for 16-bit data and b0, b1, b2, and b3 defines for 32-bit data to handle the endianess of compilers
Memory segment identifiers
SFRs
SBITs
Interrupts
Interrupt prototypes
Device specific header files (C8051Txxx_defs.h and C8051Fxxx_defs.h) use the compiler_defs.h file to allow for the header files to work with various compilers without needing to be changed. The compiler_defs.h file comes with our example code which is installed with the Integrated Development Environment (IDE). The IDE can be downloaded here:
What is compiler_defs.h?