DUEMMEGI
MCP 4 – User's manual
Contatto
2.4- Macro
A MACRO is a sequence of equations that can be inserted in more points of MCP 4 source program by using
a single call to the MACRO itself. The MACRO must first be defined in the Macros TAB of MCP IDE tool
software, then it can be referred to in the program as many times as needed (in the Equations TAB of MCP
IDE).
Each MACRO can have several arguments (parameters); the number of arguments must be the same in the
MACRO definition and in each call. The compiler will link the arguments in the call to the arguments in the
MACRO definition, in the same order they were written.
It is important to understand that:
the MACRO directive only applies to standard MCP 4 equations, it cannot be applied to SCRIPTs
the MACRO directive is an utility of the compiler, it is not a feature of MCP 4; in other words, the
compiler “explodes” each call to a MACRO into the equations specified in the definition of the
same MACRO, simply replacing each argument in the definition with the related argument passed
by the call
Up to 256 MACROs, each one with up to 32 arguments, can be defined in a MCP 4 program.
The definition of a MACRO is opened by the keyword
MACRO
followed by the name chosen for the MACRO
and, inside round brackets, the arguments to be passed to. The definition of a MACRO is closed by the
keyword
ENDMACRO
.
The required equations have to included inside this block, taking in account that the arguments in the
MACRO definition (that are variable parameters because they change from a call to the other one) cannot
have the same names reserved to the parameters or the keywords of MCP 4.
The following example defines a MACRO named DIMMER; this MACRO allow to control a dimmer output
(e.g. a MOD2DM module) whose address is OUT; the brightness level is controlled by an UP pushbutton and
by a DOWN pushbutton and, to implement the needed equation, a counter CX and a register RX are also
used; the argument list is closed by two virtual points VP1 and VP2, needed to realize the wanted function.
The MACRO definition is the following (refer to the technical sheet of MOD2DM module for more details
about the meaning of the used equations):
MACRO
DIMMER (OUT, UP, DOWN, X, VP1, VP2)
VP1 = !(UP | DOWN)
VP2 = CX,R==1 P(129)UP & P(130)DOWN & P(128)VP1
OUT = RX
ENDMACRO
If, for instance, 6 dimmer outputs must be controlled in the plant, with identical operation but with different
command inputs, the just defined MACRO can be called 6 times as follows:
DIMMER (
AO1
,
I1.1
,
I1.2
, 0,
V1
,
V2
)
DIMMER (
AO2
,
I1.3
,
I1.4
, 1,
V3
,
V4
)
DIMMER (
AO3
,
I1.5
,
I1.6
, 2,
V5
,
V6
)
DIMMER (
AO4
,
I1.7
,
I1.8
, 3,
V7
,
V8
)
DIMMER (
AO5
,
I2.1
,
I2.2
, 4,
V9
,
V10
)
DIMMER (
AO6
,
I2.3
,
I2.4
, 5,
V11
,
V12
)
As it can be seen, a different argument list is passed at each call. The compiler will “explode” this program in
a sequence of equations that is more difficult to be interpreted and to be modified. In other words, the
compiler will translate the few program lines in the previous example as follows:
V1
= !
I1.1
& !
I1.2
V2
=
C0
,R == 1 P(129)
I1.1
& P(130)
I1.2
& P(128)
V1
DUEMMEGI
s.r.l. - Via Longhena, 4 – 20139 MILANO
Tel. 02/57300377 - Fax 02/55213686 –
www.duemmegi.it
Rel.: 1.2 October 2018
Page 29 of 87