What exactly is a conditional config/compilation?
You can write code that will easily compile for different PIC processors and not have to maintain and update separate program files for each processor... since different PIC's often name their registers differently, even though they do the same thing.
Here are a couple(3) of examples... This code allows me to use either the 16F690 or the 16F1828.
The first is an example of conditional config... meaning seting the configuration registers
Code:
#IF __PROCESSOR__ = "16F1828"
#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
#endconfig
#else
#IF __PROCESSOR__ = "16F690"
#CONFIG
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
#endconfig
#ELSE
#ERROR "Program does not support " + __PROCESSOR__
#ENDIF
#endif
#msg "compiling for target " + __PROCESSOR__
an example of setting up registers...
Code:
#IF __PROCESSOR__ = "16F1828"
AnselA = 0 'and turn off analog
AnselB = 0
AnselC = 0
IOCAF = 0 'clear interrupt flag register
WDTCON=010100 'SET WDT PRESCALER
#ELSE
Ansel = 0 'and turn off analog
AnselH = 0
INTCON.0 = 0 'clear interrupt flag register
#ENDIF
An example of clearing the interrupt flag register for two different PICs...
Code:
#IF __PROCESSOR__ = "16F1828"
IOCAF = 0
#ELSE
INTCON.0 = 0 'clear interrupt flag register
#ENDIF
At compile time, only the code that fits your selected processor is actually included in the final compiled code.
Bookmarks