CPU CONFIGURATION

CPU configuration differs from writing an executable program. It is equivalent to setting dip switches or jumpers on a circuit board. The executing program has no way to change this configuration.

Attributes

XCSB "pragma cpu_config" statements are used to tell the compiler how the CPU should be configured. The compiler does not generate executable code for these statements, instead it generates special codes which it passes to chip programmer. The programmer sends these codes to a special area of the chip (seperate from the executable program) which contains hardware that configures the chip.

Configuration requires that all attributes for a specific CPU are set to a valid value. This is done by adding a list of "pragma cpu_config" statements to the XCSB program (one statement per attribute).

NOTE: All attributes for a given CPU must be specified. Attributes for different CPUs may not be mixed.

e.g.
	// valid confiuration for 16f628

	pragma cpu_config CFG_CP_OFF
	pragma cpu_config CFG_DATA_CP_OFF
	pragma cpu_config CFG_BODEN_ON
	pragma cpu_config CFG_MCLRE_ON
	pragma cpu_config CFG_PWRTE_ON
	pragma cpu_config CFG_WDT_OFF
	pragma cpu_config CFG_LVP_OFF
	pragma cpu_config CFG_INTRC_OSC_NOCLKOUT

e.g.
	// invalid confiuration for 16f628 since
	// attribute that occupies field D is not
	// specified

	pragma cpu_config CFG_CP_OFF
	pragma cpu_config CFG_DATA_CP_OFF
	pragma cpu_config CFG_BODEN_ON
	pragma cpu_config CFG_PWRTE_ON
	pragma cpu_config CFG_WDT_OFF
	pragma cpu_config CFG_LVP_OFF
	pragma cpu_config CFG_INTRC_OSC_NOCLKOUT

e.g.
	// invalid confiuration for 16f628 since
	// attribute that belongs to 16f628A is
	// specified for field A

	pragma cpu_config CFG_CP_ON
	pragma cpu_config CFG_DATA_CP_OFF
	pragma cpu_config CFG_MCLRE_ON
	pragma cpu_config CFG_BODEN_ON
	pragma cpu_config CFG_PWRTE_ON
	pragma cpu_config CFG_WDT_OFF
	pragma cpu_config CFG_LVP_OFF
	pragma cpu_config CFG_INTRC_OSC_NOCLKOUT

Specific CPU configuration attributes

Non-specific CPU configuration attributes

CPUs not supported by XCSB may still be configured using the "pragma cpu_config" statement, however instead of using named attributes it is possible to specify the attributes as a hex number. This number corresponds to the "configuration bit mask" defined in the Microchip documentation.
e.g.
	pragma cpu_config 0x3F10