#Define

#Define links commands or expressions similar to an Alias with a Identifier. The Source code can use this identifier as if it were an Expression. The compiler will replace the place holder with the corresponding expression.

#Define improves readability and adaptability of the programm or parts thereof. If you want to modify Ports for a different project; then just modify the ports only and not the whole source.

Define functions

You can define Define-Functions. The define function is a virtual function instead of a simple expression. The parameters of this virtual function are text-replaced in Expression on the right. See Example 2 and 3.

Notes
  • Defines are always global!
  • Already created Defines can be redefined like Constants. The old definition are then replaced by the new definition.

Syntax

Example 1

avr.device = attiny85
avr.clock = 8000000
avr.stack = 2
#define Button as Portb.4
dim a as byte
Button.mode = Output, pulldown
do
  if Button.debounceHigh then
    ' put your key pressed code here
    do
      waitms 100
    loop until Button.debounceLow
  end if
loop

Example 2

#define BV(n) as (1 << (n))
 
a and= BV(3)  'wird zu a and= (1 << (3))

Example 3

As of 2013.r6: Define-Functions

avr.device = attiny85
avr.clock = 8000000
avr.stack = 2
 
#define myfunc(a,b) as ((a + b) * a)
 
dim var1,var2,result as byte
 
result = myfunc(var1,var2)  '"myfunc(var1,var2)" would ((var1 + var2) * var1)
 
do
loop