Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
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
Function Pointers
Function pointers are allowed in mikroBasic PRO for AVR. The example shows how
to define and use a function pointer: 
Example: 
Example demonstrates the usage of function pointers. It is shown how to declare a
procedural type, a pointer to function and finally how to call a function via pointer.
program Example;
typedef TMyFunctionType = function (dim param1, param2 as bytedim
param3 
as wordas word ' First, define the procedural type
dim MyPtr as ^TMyFunctionType  ' This is a pointer to previously
defined type
dim sample as word
sub function Func1(dim p1, p2 as bytedim p3 as wordas word ' Now,
define few functions which will be pointed to. Make sure that param-
eters match the type definition
result = p1 and p2 or p3
end sub
sub function Func2(dim abc, def as bytedim ghi as wordas word
'
Another function of the same kind. Make sure that parameters match
the type definition
result =  abc * def + ghi
end sub
sub function Func3(dim first, yellow as bytedim monday as wordas
word
' Yet another function. Make sure that parameters match the
type definition
result =  monday - yellow - first
end sub
133
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5