Passa al contenuto principale

BitsToByte, bit to byte conversion

Questa funzione permette di convertire 8 variabili BOOL in una variabile BYTE. Lo stato di ogni bit di ingresso viene trasferito nel rispettivo bit del byte di uscita.

Approfondimenti
  • In questo topic tecniche di trasferimento array di variabili BOOL sul pannello operatore.

Descrizione​

Immagine F BitsToByte

ParametroTipoDescrizione
b0BOOLBit 0 del BYTE di Out.
b...BOOLBit ... del BYTE di Out.
b7BOOLBit 7 del BYTE di Out.
OutBYTELa funzione ritorna un BYTE.

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), LD_BitsToByte
PROGRAM LD_BitsToByte
VAR
IBit : ARRAY[0..7] OF BOOL; (* Input bits *)
OByte : BYTE; (* Output byte *)
END_VAR

Immagine programma ST_BitsToByte

LogicLab (Ptp114), IL_BitToByte
PROGRAM IL_BitToByte
VAR
IBit : ARRAY[0..7] OF BOOL; (* Input bits *)
OByte : BYTE; (* Output byte *)
END_VAR

(* ************************************************************************** *)
(* PROGRAM "IL_BitToByte" *)
(* ************************************************************************** *)
(* This program shows the use of BitsToByte function. *)
(* ------------------------------------------------------------------------- *)

LD IBit[0] (* Input bits *)
BitsToByte IBit[1], IBit[2], IBit[3], IBit[4], IBit[5], IBit[6], IBit[7]
ST OByte (* Output byte *)

(* [End of file] *)
LogicLab (Ptp114), ST_BitToByte
PROGRAM ST_BitsToByte
VAR
IBit : ARRAY[0..7] OF BOOL; (* Input bits *)
OByte : ARRAY[ 0..1 ] OF BYTE; (* Output byte *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_BitsToByte"
// *****************************************************************************
// This program shows the use of BitsToByte function.
// -----------------------------------------------------------------------------

// -------------------------------------------------------------------------
// SET BYTE
// -------------------------------------------------------------------------

OByte[0]:=BitsToByte(IBit[0], IBit[1], IBit[2], IBit[3], IBit[4], IBit[5], IBit[6], IBit[7]);

// -------------------------------------------------------------------------
// SET BYTE
// -------------------------------------------------------------------------
// The same operation as above executed directly using ST statements.

OByte[1].0:=IBit[0];
OByte[1].1:=IBit[1];
OByte[1].2:=IBit[2];
OByte[1].3:=IBit[3];
OByte[1].4:=IBit[4];
OByte[1].5:=IBit[5];
OByte[1].6:=IBit[6];
OByte[1].7:=IBit[7];

// [End of file]