beautypg.com

Pm designer operation manual, Data conversion – B&B Electronics WOP-2121V-N4AE - Manual User Manual

Page 427

background image

14

PM Designer Operation Manual

14-18

CHAPTER 14 USING MACROS

14.4.6. Data Conversion

BCD

Format

P1

= BCD(P2)

Data Type

U/UD

Function

Converts binary number P2 to a BCD number and saves the result in P1.

P1 (I/E)

The location to save the result.

P2 (I/E/C)

The binary number to be converted.

Example 1

$U100

= BCD(

0x1234

) (U)

/* The value of $U100 will be 1234. */

BIN

Format

P1

= BIN(P2)

Data Type

U/UD

Function

Converts BCD number P2 to a binary number and saves the result in P1.

P1 (I/E)

The location to save the result.

P2 (I/E/C)

The BCD number to be converted.

Example 1

$U100

= BIN(

1234

) (U)

/* The value of $U100 will be 0x1234. */

DW

Format

P1

= DW(P2)

Data Type

U/S

Function

Converts 16-bit number P2 to a 32-bit number and saves the result in P1.

P1 (I/E)

The location to save the result.

P2 (I/E/C)

The 16-bit number to be converted.

Example 1

$U100

= DW(

12345

) (S)

/* The value of $U100 will be 12345 and the value of $U101 will be 0. */

Example 2

$U200

= DW(

-12345

) (S)

/* The value of $U200 will be -12345 and the value of $U201 will be

0xFFFF. */

W

Format

P1

= W(P2)

Data Type

UD/SD

Function

Converts 32-bit number P2 to a 16-bit number and saves the result in P1. The truncation error
may occur.

P1 (I/E)

The location to save the result.

P2 (I/E/C)

The 32-bit number to be converted.

Example 1

$U100

= W(

0x12345678

) (UD)

/* The value of $U100 will be 0x5678 */

Example 2

$U200

= W(

-12345

) (SD)

/* The value of $U200 will be -12345 */