Instructions

187 C-Control Pro IDE
© 2013 Conrad Electronic
4.2.7 Functions
In order to structure a larger program it is separated into several sub-functions.
This not only improves the readability but allows to combine all program instruc-
tions repeatedly appearing in functions. A program does in any case contain the
function "main", which is started in first place. After that other functions can be
called up.
A simple example:
void func1(void)
{
// instructions in function func1
.
.
}
void main(void)
{
// function func1 will be called up twice
func1();
func1();
}
Parameter Passing
In order to enable functions to be flexibly used they can be set up parametric. To do this the para-
meters for the function are separated by commas and passed in parenthesis after the function name.
Similar to the variables declaration first the data type and then the parameter name are stated. If no
parameter is passed then void has to be set into the parenthesis.
An example:
void func1(word param1, float param2)
{
Msg_WriteHex(param1); // first parameter output
Msg_WriteFloat(param2); // second parameter output
}
Similar to local variables passed parameters are only visible within the function itself.
In order to call up function func1 by use of the parameters the parameters for call up should be writ-
ten in the same succession as they have been defined in func1. If the function does not get paramet-
ers the parenthesis will stay empty.
void main(void)
{
word a;
float f;
func1(128,12.0); // you can passs numerical constants
a=100;
f=12.0;
func1(a+28,f); // or yet variables too and even numerical expressions