Vai al contenuto

BitsToByte, bit to byte conversion

Vai all indice del manuale di programmazione
Tipo: Funzione
Libreria LogicLab: eLLabUtyLib
Libreria Codesys: Non disponibile

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.

Descrizione

b0 (BOOL) Bit 0 del BYTE di Out.
b… (BOOL) Bit … del BYTE di Out.
b7 (BOOL) Bit 7 del BYTE di Out.

La funzione ritorna un BYTE.

Immagine F BitsToByte

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]
Was this article helpful?