函数
15.3 Function
Use of functions can simplify the code structure, improve the readability and reuse rate of code. The user can define the program segment as a new function that needs to be executed frequently so that it can be conveniently called in the main program at any time.
15.3.1 Function definition
15.3.1.1 PROC
PROC represents a function with no return value, defined as:
SCOPE PROC RoutineName()
…
…
//do something
…
…
ENDPROC
Where:
1. SCOPE is the function scope, which supports both the GLOBAL and LOCAL;
2. PROC is the defining keyword for functions with no return value;
3. RoutineName is the function name. The naming rules are the same as the variable naming rules. For details, see the Variable naming rules.
Auxiliary programming, and PROC can be inserted in the following ways:

15.3.1.2 FUNC
FUNC is a function with a return value, defined as:
SCOPE FUNC RET RoutineName()
…
…
//do something
…
…
ENDFUNC
Where:
1. SCOPE is the function scope, which supports both the GLOBAL and LOCAL;
2. FUNC is the defining keyword for functions with no return value;
3. RET is the return value type;
4. RoutineName is the function name. The naming rules are the same as the variable naming rules. For details, see the Variable naming rules.
Auxiliary programming, and FUNC can be inserted in the following ways:
15.3.1.3 TRAP
TRAP is an interrupt function with no return value, defined as:
TRAP TrapName()
…
…
//do something
…
…
ENDTRAP
Where:
1. TRAP is the definition keyword for interrupt functions with no return value;
4. TrapName is the function name. The naming rules are the same as the variable naming rules. For details, see the Variable naming rules.
Auxiliary programming, and TRAP can be inserted in the following ways:
15.3.2 Function call
When calling a function, enter the function name directly in the program editor, for example:
RoutineName()
Note:
-
Only other GLOBAL-level functions in this project or LOCAL-level functions in this module file can be called. Recursive calls are not supported. Cross calls between two sub-functions is also not supported.
-
Calling a function is treated as a separate program command in the compiler.
-
It is not allowed to define a function in a function.