Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
19
Добавлен:
11.10.2020
Размер:
3.39 Mб
Скачать

The UTIL.LIB Library

335

UTIL.LIB Library

 

 

 

14The UTIL.LIB Library

14.1 UTIL.LIB Library

This library contains an additional collection of various blocks which can be used for BCD conversion, bit/byte functions, mathematical help functions, as controller, signal generators, function manipulators and for analogue value processing.

14.2 BCD conversion

A byte in the BCD format contains integers between 0 and 99. Four bits are used for each decimal place. The ten decimal place is stored in the bits 4-7. Thus the BCD format is similar to the hexadecimal presentation, with the simple difference that only values between 0 and 99 can be stored in a BCD byte, whereas a hexadecimal byte reaches from 0 to FF.

An example: The integer 51 should be converted to BCD format. 5 in binary is 0101, 1 in binary is 0001, which makes the BCD byte 01010001, which corresponds to the value $51=81.

14.2.1BCD_TO_INT

This function converts a byte in BCD format into an INT value:

The input value of the function is type BYTE and the output is type INT.

Where a byte should be converted which is not in the BCD format the output is -1.

Examples in ST:

i:=BCD_TO_INT(73);

(* Result is

49

*)

k:=BCD_TO_INT(151);

(* Result is

97

*)

l:=BCD_TO_INT(15);

(* Output -1, because it is not

in BCD format *)

 

 

 

14.2.2INT_TO_BCD_

This function converts an INTEGER value into a byte in BCD format:

The input value of the function is type INT, the output is type BYTE.

The number 255 will be outputted where an INTEGER value should be converted which cannot be converted into a BCD byte.

Examples in ST:

i:=INT_TO_BCD(49);

(* Result is 73 *)

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32