Passa al contenuto principale

ByteToBit, Byte to bit conversion

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​

Immagine FB ByteToBit

ParametroTipoDescrizione
InBYTEValore da convertire.
b0BOOLBit 0 del BYTE di In.
b...BOOLBit ... del BYTE di In.
b7BOOLBit 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

Immagine programma FBD_ByteToBit

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]