AKD BASIC User Guide | 3 AKDBASICLanguage
3.3.3 Function Definition
For a function such as sum_squares, a typical definition is:
function sum_squares(i,j as integer) as integer
sum_squares = i^2 + j^2
end function
The function above returns a value of type integer. The value of the function is assigned by
assigning to the name of the function, as if it were a variable.
It is not legal to use the function name as a variable name on the left-hand-side of
an assignment - a function name on the leftt-hand-side is always an INVOCATION
of that function.
There must be at least one statement in the function that assigns a value to the function. It is
not possible to detect at compile-time if the statement will actually execute. Functions are
invoked by name, as in print sum_squares(3,4). This is syntactically identical to an array ref-
erence.
3.3.4 Interrupt Handler Definition
The Interrupt statment marks the beginning of an Interrupt Service Routine. The Interrupt Serv-
ice Routine is defined by a program structure resembling a subroutine. The interrupt feature per-
mits execution of a user-defined subroutine upon receipt of a hardware interrupt signal or a pre-
defined interrupt event.
Interrupts are triggered by pre-defined events or external hardware sources. The interrupt-
source-name and interrupt enable flag are unique for each interrupt source. For a list of interrupt
sources see Interrupt {Source}.
Receiving an interrupt will suspend program execution and the interrupt service routine will be
executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag.
Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically
disabled until it is enabled again in your program.
Main
DRV.TIME = 0
INTR.DIN1LO = 1 'enables interrupt
while 1
pause(0.5)
DOUT1.STATEU=0 : Pause(0.005):DOUT1.STATEU=1
wend
end main
'the following interrupt defines what occurs
for interrupt DIN1LO
Interrupt DIN1LO
print "I'm awake"
If DRV.TIME > 10 then
print "OK. That's it."
else
INTR.DIN1LO = 1 're-enables interrupt
end if
End Interrupt
25 Kollmorgenâ„¢ | March 30, 2012