Often I write programs that can have multiple modes based on a constant or I just want to vary a parameter and rerun the program. Since the schematic is the main view of the project, it is often beneficial to see the current constants or parameters right on the schematic. This is done for components such as the DelSig ADC where the resolution of the first configuration is displayed. This same concept can be used for software only constants as well.
The Constants component is a very simple way to display constants used by the firmware on the schematic. Also this allows you to change firmware parameters without changing actual source code. I have created an example component that allows the user to assigns names and values to up to four constants. The component consists of just a symbol and a header file. Below is what the component would look like on the schematic. The four constants have already been assigned names, DEBUG, LOOP, DELAY, and COUNT, as well as values.

Figure 1 Example Project Constants Component
The configuration is very simple. The user simply assigns a name and value. The header file is automatically generated. The constants defined below will have the instance name pre-pended on the name. For example, the LOOP constant name will be MyConstants_LOOP .

Figure 2 Configuration dialog of Project Constants Component
The generated header file would look like this using the configuration in Figure 2.
#defineMyConstants_DEBUG 0
#defineMyConstants_LOOP 100
#defineMyConstants_DELAY 95
#defineMyConstants_COUNT 5
The constants can then be used throughout the firmware, just by including the MyConstants.h header file. Below is an example of a code snippet that makes use of the constants provided in MyConstants.h.
for(i = 0; i < MyConstants_LOOP; i++)
{
LCD_Position(1,5);
LCD_PrintHexUint8(i);
CyDelay(MyConstants_DELAY);
}
The same concept could be used for user created components for a specific application. For example a project phase component that displays on the schematic whether the project is in the release or debug phase. The header file would contain the #define statements for the different mode.

Figure 3 Project Phase Component
Other similar components can easily be generated by the user, with just some simple basic knowledge of how to create components. For example if you wanted a waveform generator to change the waveform without changing code.

Figure 4 Application Mode Example
The header file would contain the following:
#defineAppMode_Mode 2
#defineAppMode_SINE 0
#defineAppMode_SQUARE 1
#defineAppMode_TRIANGLE 2
The firmware would look at the AppMode_Mode constant to determine which waveform to generate, requiring no code changes.
This is just one simple trick to make a project more flexible and easier to change its operation without editing code. It is also a good way to demo an application to a customer. The user can then try different operations without editing code. The MyConst component is generic and can be used with any project. The ProjectPhase and AppMode components can easily be created by the user in a matter of minutes.
By Mark Hastings