Passa al contenuto principale

BytesToWord, byte to word conversion

Questa funzione permette di convertire due variabili BYTE in una variabile WORD. L'operando MSB è trasferito negli 8 bits alti, l'operando LSB è trasferito negli 8 bits bassi di Out.

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

Descrizione​

Immagine funzione BytesToWord

ParametroTipoDescrizione
MSBBYTEMSB del valore in uscita.
LSBBYTELSB del valore in uscita.
OutWORDLa funzione ritorna una WORD.

Esempi​

Come utilizzare gli esempi.
Nell'esempio due variabili BYTE con valore 16#12 e 16#34 sono trasferite in una variabile WORD il risultato sarà 16#1234.

LogicLab (Ptp114), IL_BytesToWord
PROGRAM IL_BytesToWord
VAR
High : BYTE := 16#12; (* MSB byte *)
Low : BYTE := 16#34; (* LSB byte *)
Result : WORD; (* Compress result *)
END_VAR

(* ************************************************************************** *)
(* PROGRAM "IL_BytesToWord" *)
(* ************************************************************************** *)
(* This program shows the use of BytesToWord function. *)
(* ------------------------------------------------------------------------- *)

LD High (* MSB byte *)
BytesToWord Low
ST Result (* Compress result *)

(* [End of file] *)
LogicLab (Ptp114), ST_BytesToWord
PROGRAM ST_BytesToWord
VAR
High : BYTE := 16#12; (* MSB byte *)
Low : BYTE := 16#34; (* LSB byte *)
Result : ARRAY[0..1] OF WORD; (* Compress result *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_BytesToWord"
// *****************************************************************************
// This program shows the use of BytesToWord function.
// -----------------------------------------------------------------------------

// -------------------------------------------------------------------------
// COMPRESS BYTE
// -------------------------------------------------------------------------
// Compress byte using the FB.

Result[0]:=BytesToWord(High, Low); //Compress result

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

Result[1]:=(TO_WORD(High)*256)+TO_WORD(Low); //Compress result

// [End of file]