246
Manual – IPOSplus®
18
Setting bits and output terminals
Compiler – Examples
18
Compiler – Examples
18.1 Setting bits and output terminals
There are two ways of setting individual bits in variables:
1. The _BitSet ( Hx, y ) function sets bit y in variable x to one.
2. The bit-by-bit OR operation Hx ¦ K sets those bits in variable x to one which are also
set to one in constant K.
In both cases, the legibility of the program can be improved if the bit position or the con-
stant is defined symbolically. Bit setting functions are mainly used for setting binary unit
outputs. Therefore, in the following example, variable H481 (StdOutpIPOS) will be used
as the target variable of the operation. Variable H480 (OptOutpIPOS) would be used ac-
cordingly to address the outputs of the option. In the example, the output terminal DO02
of the basic unit is to be set.
The source text can be simplified even further if symbolic designators are used for the
corresponding statements as well as the variables and constants:
Using _BitSet():
#include <const.h>
#include <io.h>
// MOVIDRIVE A
#include <iob.h> // MOVIDRIVE B
#define SetDO02 _BitSet( StdOutpIPOS, 2);
main()
{
Set
DO02
}
If several outputs are to be set at the same time, then you can either call the _BitSet()
function several times in succession or use the bit-by-bit OR logic operation for this. In
the second case, one statement will suffice. This reduces the amount of code and thus
also has a positive effect on the program run time.
The following example uses the OR operation to set DO01 and DO02 at the same time.
Using the OR operation:
#include <const.h>
#include <io.h>
// MOVIDRIVE A
#include <iob.h> // MOVIDRIVE B
main()
{
StdOutpIPOS ¦= DO01 ¦ DO02;
}
Using _BitSet()
Using the OR operation
#include <const.h>
#include <io.h>
// MOVIDRIVE A
#include <iob.h> // MOVIDRIVE B
main()
{
_BitSet( StdOutpIPOS, 2 );
}
#include <const.h>
#include <io.h>
// MOVIDRIVE A
#include <iob.h> // MOVIDRIVE B
main()
{
StdOutpIPOS ¦= DO02;
}
P
i
f
kVA
Hz
n
P
i
f
kVA
Hz
n