By using #define
, you can assign names to values before compiling.
#define motorport 4
Low motorport
In the example above, motorport
will be compiled as 4. You can also use Const
for similar tasks. However, Const
will use data memory; #define
will only use program memory.
CONST motorport = 4 Low motorport
The following example uses #define
for replacing a line of code:
#define FLAGREG1 2 #define f_led FLAGREG1.BIT0 #define calc (4+i)*256 f_led = 1 ' Set FLAGREG1’s bit zero to 1. If f_led = 1 Then f_led = 0 ' Make it easier to read. j = calc ' Calculations can be simplified
NOTE
The “name” argument in a #define
statement is not case-sensitive. For example, #define ALPHA 0
and
#define alpha 0
do not define different constants. They both define the same constant.
See also Const.