Vai all indice del manuale di programmazione
Tipo:
Blocco funzione
Libreria LogicLab:
eLLabUtyLib
Libreria Codesys:
Non disponibile
Questo blocco funzione permette di convertire una variabile BYTE in 8 variabili BOOL. Lo stato di ogni bit della variabile di ingresso viene trasferito nella rispettiva variabile BOOL di uscita.
Descrizione
In (BYTE) Valore da convertire.
b0 (BOOL) Bit 0 del BYTE di In.
b… (BOOL) Bit … del BYTE di In.
b7 (BOOL) Bit 7 del BYTE di In.

Esempi
Come utilizzare gli esempi.
Nell’esempio 8 variabili BOOL sono trasferite in una variabile BYTE, allo stato di ogni IBit corrisponde il relativo bit nella variabile OByte.
LogicLab (Ptp114), FBD_Byte
ToBit
PROGRAM FBD_ByteToBit
VAR
IByte : BYTE; (* Input byte *)
OBit : ARRAY[0..7] OF BOOL; (* Output bits *)
BDec : ByteToBit; (* Byte decompress *)
END_VAR

LogicLab (Ptp114), IL_Byte
ToBit
PROGRAM IL_ByteToBit
VAR
IByte : BYTE; (* Input byte *)
OBit : ARRAY[0..7] OF BOOL; (* Output bits *)
BDec : ByteToBit; (* Byte decompress *)
END_VAR
(* ************************************************************************** *)
(* PROGRAM "IL_ByteToBit" *)
(* ************************************************************************** *)
(* This program shows the use of ByteToBit function block. *)
(* ------------------------------------------------------------------------- *)
LD IByte (* Input byte *)
ST BDec.In
CAL BDec (* Call the function block *)
(* Store the result. *)
LD BDec.b0
ST OBit[0] (* Output bits *)
LD BDec.b1
ST OBit[1] (* Output bits *)
LD BDec.b2
ST OBit[2] (* Output bits *)
LD BDec.b3
ST OBit[3] (* Output bits *)
LD BDec.b4
ST OBit[4] (* Output bits *)
LD BDec.b5
ST OBit[5] (* Output bits *)
LD BDec.b6
ST OBit[6] (* Output bits *)
LD BDec.b7
ST OBit[7] (* Output bits *)
(* [End of file] *)
LogicLab (Ptp114), ST_Byte
ToBit
PROGRAM ST_ByteToBit
VAR
IByte : BYTE; (* Input byte *)
OBit : ARRAY[ 0..1, 0..7 ] OF BOOL; (* Output bits *)
BDec : ByteToBit; (* Byte decompress *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_ByteToBit"
// *****************************************************************************
// This program shows the use of ByteToBit function block.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// DECOMPRESS BYTE
// -------------------------------------------------------------------------
BDec(In:=IByte);
OBit[0,0]:=BDec.b0; //Output bits
OBit[0,1]:=BDec.b1; //Output bits
OBit[0,2]:=BDec.b2; //Output bits
OBit[0,3]:=BDec.b3; //Output bits
OBit[0,4]:=BDec.b4; //Output bits
OBit[0,5]:=BDec.b5; //Output bits
OBit[0,6]:=BDec.b6; //Output bits
OBit[0,7]:=BDec.b7; //Output bits
// -------------------------------------------------------------------------
// DECOMPRESS BYTE
// -------------------------------------------------------------------------
// The same operation as above executed directly using ST statements.
OBit[1,0]:=IByte.0; //Output bits
OBit[1,1]:=IByte.1; //Output bits
OBit[1,2]:=IByte.2; //Output bits
OBit[1,3]:=IByte.3; //Output bits
OBit[1,4]:=IByte.4; //Output bits
OBit[1,5]:=IByte.5; //Output bits
OBit[1,6]:=IByte.6; //Output bits
OBit[1,7]:=IByte.7; //Output bits
// [End of file]