User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
184
3.4 Compile Time Directives
3.4.1 Compiler Directives
MCL supports compile time directives. Compile time directives can be used to selectively include
or exclude parts of a program which can be very useful. During compile time you can dene
parts of the program to compile or not.
3.4.2 Conditional Compiling
If you’ve written a program to display temperature from a sensor, you may want versions
for Celsius and Fahrenheit. Most of the code is identical, but some constants, variables and
subroutines may differ.
Conditional compiling lets you set a “switch” in your program that controls compiling. You can
have different constants, variables, or even different sections of code compiled depending on the
switch or switches that you set.
#IF .. #ENDIF
#IF expression
optional code
#ENDIF
Example
Similar to IF..THEN conditional branch, but species code to be compiled if the expression is true.
In the example below the constant temp is set to 1. During compile time the #IF will test temp
to see if it is true. In the example below will return true so the following block of code is included
during compile time.
temp con 1
#IF temp=1
..optional code..
#ENDIF
..rest of program..