DUEMMEGI
MCP 4 – User's manual
Contatto
3- SCRIPT
3.1- Summary
Scripts allow to implement sections of program that will be executed in sequential mode by MCP 4. Each
Script can be started (“triggered”) by an event or it can be executed every a well specified time period. Each
defined script must be numbered; up to 127 scripts may be defined.
The scripts
must be used only to execute functions that cannot be realized by the standard equations
of MCP 4
. The duration of a script must be lower than 500msec, on the contrary MCP 4 will interrupt its
execution (and it will set the related virtual point V2004). Therefore, be aware of the loops nested into a script.
Keyword
Meaning
SCRIPT…
ENDSCRIPT
Enclose the instructions belonging to the script: SCRIPT declares the start and ENDSCRIPT
declares the end
TRIGGER
Specify the event that starts the SCRIPT or the time execution period in seconds
EXIT
Force the exit from the script
VAR
Declare a local variable, therefore not shared with the other scripts
GLOBAL VAR
Declare a global variable, therefore shared with all other scripts
EXTERN VAR
The specified variable has been declared as global in another script
&, |, ^, !
logical operators (no parenthesis are allowed and no more than one operation for each line is
allowed)
+, -, *, /, =
mathematical operators (no parenthesis are allowed and no more than one operation for
each line is allowed)
IF…THEN…ELSE…
ENDIF
Condition. IF and ENDIF enclose the block. An IF must be always closed by an ENDIF
>,>=,==,<,<=,
!=
Comparison operators (greater than, greater or equal to, equal to, less than, less or equal to,
not equal to)
CARRY
Bit (flag) whose value is 1 if the result of the previous operation exceeds the value 65535
(overflow) or if the result of the previous operation is negative (underflow) or if a division by 0
occurred; the value of this bit is 0 in all other cases
ZERO
bit (flag) whose value is 1 if the result of the previous operation is zero; the value of this bit is
0 in all other cases
DEFINE
assign a name to a variable or to a parameter or to a constant
GOTO
unconditional jump
CALL
jump to a subroutine or function (which is a section of a script); from a script, it is possible to
call a subroutine contained into another script
SUB…ENDSUB
Enclose a block of instructions as subroutine or as function; the subroutines that have been
declared in a script can be “seen” and used by any other script
RET
Exit from a subroutine or function
BIT(x)
Declare that parameter x of a subroutine or function or the value returned by a function is a
bit; the declaration BIT(x) applies to subroutines or functions only
WORD(x)
Return the number of the Word where the point x is mapped
[ptr]
Pointer: it returns the content of the Word whose address is the value of the variable inside
the square brackets (ptr in this case); in other words, ptr points to the Word address and [ptr]
is the content of the “pointed” Word (see examples)
@WORD k
It returns the content of the Word k, where k is a constant value in the range 0 to 32767
@RAM k
It returns the content of the two consecutive bytes starting at address is k, where k is a
constant value in the range 0 to 65535
SWAP(x)
exchange the high byte with the low byte of specified Word (x)
RANDOM(0)
Function that returns a 16-bit random number
BMASK(x)
Function that returns a 16 bit number having, in its binary format, only one bit set to 1 at the
position of (x-1)%16 (that means (x-1) module 16); this function is useful for bit operations
DUEMMEGI
s.r.l. - Via Longhena, 4 – 20139 MILANO
Tel. 02/57300377 - Fax 02/55213686 –
www.duemmegi.it
Rel.: 1.2 October 2018
Page 31 of 87