Техническая Спецификация для Mikroelektronika MIKROE-350
Example
Here’s an example procedure which transforms its input time parameters, preparing
them for output on Lcd:
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:
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.
procedural type, a pointer to function and finally how to call a function via pointer.
program Example;
typedef TMyFunctionType = function (dim param1, param2 as byte, dim
param3
param3
as word) as word ' First, define the procedural type
dim MyPtr as ^TMyFunctionType ' This is a pointer to previously
defined type
dim sample as word
defined type
dim sample as word
sub function Func1(dim p1, p2 as byte, dim p3 as word) as word ' Now,
define few functions which will be pointed to. Make sure that param-
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 byte, dim ghi as word) as word
'
Another function of the same kind. Make sure that parameters match
the type definition
the type definition
result = abc * def + ghi
end sub
sub function Func3(dim first, yellow as byte, dim monday as word) as
word
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