Mikroelektronika MIKROE-442 Datenbogen
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
201
Now we could call it to calculate, say, 3
12
:
tmp = power(3, 12)
Procedures
Procedure is declared like this:
sub procedure procedure_name(parameter_list)
[ local declarations ]
procedure body
end sub
procedure_name
represents a procedure’s name and can be any valid identifier. Within parentheses,
parameter_
list
is a formal parameter list similar to variable declaration. In mikroBasic PRO for dsPIC30/33 and PIC24, parameters
are always passed to procedure by value; to pass argument by address, add the keyword
byref
ahead of identifier.
Local declarations
are optional declaration of variables and/or constants, local for the given procedure.
Procedure
body
is a sequence of statements to be executed upon calling the procedure.
Calling a procedure
A procedure is called by its name, with actual arguments placed in the same sequence as their matching formal
parameters. The compiler is able to coerce mismatching arguments to the proper type according to implicit conversion
rules. Upon procedure call, all formal parameters are created as local objects initialized by the values of actual
arguments.
Procedure call is a self-contained statement.
Example:
Here’s an example procedure which transforms its input time parameters, preparing them for output on Lcd:
sub procedure time_prep(dim byref sec, min, hr as byte)
sec = ((sec and $F0) >> 4)*10 + (sec and $0F)
min = ((min and $F0) >> 4)*10 + (min and $0F)
hr = ((hr and $F0) >> 4)*10 + (hr and $0F)
end sub
A function can return a complex type. Follow the example bellow to learn how to declare and use a function which
returns a complex type.