15.07.2013 Views

Automatic control function programming manual ladder language

Automatic control function programming manual ladder language

Automatic control function programming manual ladder language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

General Purpose Functions<br />

6.3 BCD —> Binary Conversion bcd_bin<br />

Syntax<br />

bdc_bin (BCD_code)<br />

Code: Operand or numerical expression in BCD code.<br />

Operation<br />

The operand, considered as signed, is extended on 32 bits before being placed in the stack. Conversion can only be<br />

performed on an operand in which each half-byte does not exceed the value 9 (in BCD code). If an error is detected,<br />

the <strong>function</strong> returns -1.<br />

Example:<br />

%V0L.= bcd_bin(%V4.L)<br />

%V4.L contains the value 12345678 in BCD code.<br />

Memory representation of %V4.L: 0001-0010-0011-0100-0101-0110-0111-1000<br />

1 2 3 4 5 6 7 8<br />

12345678 = = 0xBC614E<br />

Memory representation of %V0.L: 0000-0000-1011-1100-0110-0001-0100-1110<br />

0 0 B C 6 1 4 E<br />

! CAUTION<br />

When the BCD operand is on 8 or 16 bits and the last half-byte is > 8, it is necessary to<br />

mask the parameter with the value 0xFF or 0xFFFF so as not to propagate the sign bit.<br />

Example: bcd_bin(%V0.B & 0xFF) ; bcd_bin(%V0.W & 0xFFFF)<br />

Return Code<br />

If OK<br />

Conversion result<br />

Error<br />

-1: operand not in BCD code, one of the half-bytes > 9.<br />

en-938846/7 6 - 5<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!