4.3 Macro Operation: Keypad

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Chapter 4 Macro Function|ScrEdit Software User Manual

Fig. 4.2.13 Fig. 4.2.14 Fig. 4.2.15 Fig. 4.2.16


Data conversion Comparison Flow control Bit setting

Fig. 4.2.17 Fig. 4.2.18


Communication Others

„ Keypad

For the convenience of editing macro, ScrEdit allows the users to edit Macro by using keypad (key in
manually). ScrEdit will check the validity automatically. If there are any errors, a warning dialog box will
pop up to remind the users. There are no limit spaces between operand and operation symbol for the
users to key in. After finishing inputting, ScrEdit will convert the macro to the best format automatically
after updating the macro or pressing Enter key. But please notice that ScrEdit has not verified the
macro yet at this time.

4.3 Macro Operation

„ Definition

WORD 16 Bit data (It is made up of continuous 2 bytes, i.e. 16 bits, b15~b0. It can be used to
represent 0000~FFFF of hexadecimal system.

DWORD, DW 32 Bit data (It is made up of continuous 2 words, i.e. 32 bits, b31~b0. It can be used to
represent 00000000~FFFFFFFF of hexadecimal.)

BYTE 8 Bit data (It is made up of continuous 2 nibbles, i.e. 8 bits, b7~b0. It can be used to
represent 00~FF of hexadecimal system.)

Signed A signed value is a numeric value with polarity. It means that the value is interpreted as
essentially the 'plus' sign that can be found in front of a positive number and the
'minus' sign that can be found in front of a negative number.

Revision 05/30/2006, EH00 4-9


Chapter 4 Macro Function|ScrEdit Software User Manual

„ Arithmetic Operation

Arithmetic Operation divides into two parts: Integer Operation and Floating Point Operation.

Each operand can be internal memory or constant. But it shall be internal memory only when outputting.
Please refer to following table 4.3.1 and examples below for more information.
Command Equation Description Remark
+ V1=V2 + V2 Addition The calculation result can
Integer Operation

be stored as signed or
- V1=V2 - V3 Subtraction unsigned WORD and
DWORD.
* V1 = V2 * V3 Multiplication When the data exceeds
the length of designated
/ V1 = V2 / V3 Division
unit, the data out of range
% V1 = V2 % V3 Get Remainder will be discarded.

FADD V1=FADD(V2, V3) Addition Floating Point Operation is


Floating Point

the operation of signed 32


FSUB V1=FSUB(V2, V3) Subtraction
Operation

Bit data.
FMUL V1=FMUL(V2, V3) Multiplication
FDIV V1=FDIV(V2, V3) Division
FMOD V1=FMOD(V2, V3) Get Remainder

Table 4.3.1 Arithmetic command table

„ +, FADD

Addition

Equation: V1 = V2 + V3[(Signed | DW)]

V1 = FADD(V2, V3) (Signed DW)

Perform the addition on V2 and V3, and store the addition result in V1.

Example:

The value contained within the internal memory address #2 plus 1

$2 = $2 + 1

The values contained within the internal memory address #1 and #2 are combined and the total is
stored in the address #3.

$3 = $2 + $1

The value contained within the internal memory address #4 plus 1.9

$4 = FADD($4, 1.9)

The floating point values contained within the internal memory address #4 and #5 are combined and
the total is stored in the address #6.

$6 = FADD($5, $4)

4-10 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

„ -, FSUB

Subtraction

Equation: V1 = V2 - V3[(Signed | DW)]

V1 = FSUB(V2, V3) (Signed DW)

Perform the subtraction of V2 and V3, and store the subtraction result in V1.

Example:

Subtract 1 form the value contained within the internal memory address #2

$2 = $2 - 1

The value contained within the internal memory address #1 is subtracted from the value contained
within the internal memory address #2 and the result of this calculation is stored in the internal memory
address #3.

$3 = $2 - $1

Subtract 1.9 form the value contained within the internal memory address #4

$4 = FSUB($4, 1.9)

The floating point value contained within the internal memory address #4 is subtracted from the floating
point value contained within the internal memory address #5 and the result of this calculation is stored
in the internal memory address #6.

$6 = FSUB($5, $4)

„ *, FMUL

Multiplication

Equation: V1 = V2 * V3[(Signed | DW)]

V1 = FMUL(V2, V3) (Signed DW)

Perform the multiplication of V2 and V3, and store the multiplication result in V1.

Example:

The value contained within the internal memory address #2 multiplied by 2

$2 = $2 * 2

The value contained within the internal memory address #2 multiplied by #1 and the result of this
calculation is stored in the address #3.

$3 = $2 * $1

The value contained within the internal memory address #4 multiplied by 1.5

$4 = FMUL($4, 1.5)

The floating point value contained within the internal memory address #4 multiplied by #5 and the result
of this calculation is stored in the address #6.

$6 = FMUL($5, $4)

Revision 05/30/2006, EH00 4-11


Chapter 4 Macro Function|ScrEdit Software User Manual

„ /, FDIV

Division

Equation: V1 = V2 / V3[(Signed | DW)]

V1 = FDIV(V2, V3) (Signed DW)

Perform the division of V2 and V3, and store the division result in V1. The value contained
within V3 cannot be equal to 0(zero).

Example:

Subtract 1 form the value contained within the internal memory address #2

$2 = $2 - 1

The value contained within the internal memory address #2 divided by 5 and the result of this
calculation is stored in the address #3.

$3 = $2 / 5

Subtract 1.9 form the value contained within the internal memory address #4

$4 = FSUB($4, 1.9)

The value contained within the internal memory address #4 divided by 4.3 and the result of this
calculation is stored in the address #6.

$6 = FDIV($4, 4.3)

„ %, FMOD

Get Remainder

Equation: V1 = V2 % V3[(Signed | DW)]

V1 = FMOD(V2, V3) (Signed DW)

Perform the division of V2 and V3, and store the remainder in V1. The value contained within V3
cannot be equal to 0(zero).

Example:

Subtract 1 form the value contained within the internal memory address #2

$2 = $2 - 1

The value contained within the internal memory address #2 divided by 5 and the remainder of the result
of this calculation is stored in the address #3.

$3 = $2 % 5

Subtract 1.9 form the value contained within the internal memory address #4

$4 = FSUB($4, 1.9)

The value contained within the internal memory address #4 divided by 4 and the remainder of the result
of this calculation is stored in the address #6.

$6 = FMOD($4, 4)

4-12 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

„ ADDSUMW

Repeated Addition

Equation: V1 = ADDSUMW(V2, V3)[(DW)]

Perform the addition on V2, V2+1, V2+2, …, V2+V3, and store the repeated addition result in V1.

Example:

$2 = 1

$3 = 2

$4 = 3

$5 = 3

$0 = ADDSUMW($2, $5)

Add up the values contained within the internal memory address #2, #3, #4 and #5 (3 Words started
from address #2) and the grand total is stored in the address #0. The value of the grand total is equal to
6.

„ Logical Operation

Six logical operations includes OR, AND, XOR, NOT, Shift-left and Shift-right. SHR. There are three
operands for each operation. Each operand can be internal memory or constant. But it shall be internal
memory only when outputting. The unit can be Word and Double Word. Please refer to following table
4.3.2 and examples below for more information.
Command Equation Description Remark
| V1 = V2 | V3 Logical OR operation The calculation result can be
&& V1 = V2 && V3 Logical AND operation stored as WORD and
DWORD.
^ V1 = V2 ^ V3 Logical XOR operation
NOT V1 = NOT V2 Logical NOT operation
<< V1 = V2 << V3 Logical Shift-left operation
>> V1 = V2 >> V3 Logical Shift-rightt operation

Table 4.3.2 Logical operation command table

„ | Operand

Logical OR operation

Equation: V1 = V2 | V3[(DW)]

Perform the logical OR operation on V2 and V3 and save the result of this calculation in V1.

Example:

$2 = F000H

$4 = 0F00H

$2 = $2 | $4

Store the result of $2 in FF00H

Revision 05/30/2006, EH00 4-13


Chapter 4 Macro Function|ScrEdit Software User Manual

„ && Operand

Logical AND operation

Equation: V1 = V2 && V3[(DW)]

Perform the logical AND operation on V2 and V3 and save the result of this calculation in V1.

Example:

$2 = F000H

$4 = 0F00H

$2 = $2 && $4

Store the result of $2 in 0000H

„ ^ Operand

Logical XOR operation

Equation: V1 = V2 ^ V3[(DW)]

Perform the logical XOR operation on V2 and V3 and save the result of this calculation in V1.

Example:

$2 = F100H

$4 = 0F00H

$2 = $2 ^ $4

Store the result of $2 in FE00H

„ NOT

Logical NOT operation

Equation: V1 = NOT V2 [(Signed | DW)]

Perform the logical NOT operation on V2 and V3 and save the result of this calculation in V1.

Example:

$2 = F100H

$4 = NOT $2

Store the result of $$ in 0EFFH

„ << Operand

Logical Shift-left operation

Equation: V1 = V2 << V3[(DW)]

Shift V2 (WORD/DWORD) data to left (number of bit is V3). The result of this calculation is
stored in V1.

Example:

4-14 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

$2 = F100H

$2 = $2 << 4

$2 shift-left 4 bits and becomes 1000H

„ >> Operand

Logical Shift-right operation

Equation: V1 = V2 >> V3[(DW)]

Shift V2 (WORD/DWORD) data to right (number of bit is V3). The result of this calculation is
stored in V1.

Example:

$2 = F100H

$2 = $2 >> 4

$2 shift-right 4 bits and becomes 0F10H

„ Data Transfer

There are five commands for data transfer, including =, BMOV, FILL, CHR and FMOV. Please refer to
following table 4.3.3 and examples below for more information.
Command Equation: Description Remark
Data type for V1 only can be
= V1 = V2 Transfer data
P, M
Data type for A1 and A2 only
BMOV BMOV(V1, V2, V3) Block move
can be P, M
FILL FILL(V1, V2, V3) Fill the memory
CHR CHR(V1, "V2") Convert text to ASCII code V2 is a input string of texts
FMOV V1 = FMOV(V2) Transfer floating point data

P- PLC address, M- Internal memory, C- Constant

Table 4.3.3 Data transfer command table

„ = Operand

Transfer data

Equation: V1 = V2[(Signed DW | DW)]

Transfer data from V2 to V1. No data change within A2 after executing MOV command.

Example:

The data within the internal memory address $0 is designated the constant 4.

$0 = 4

The data within the internal memory address #4 is designated the same as the data within the internal
memory address $2.

$4 = $2

Revision 05/30/2006, EH00 4-15


Chapter 4 Macro Function|ScrEdit Software User Manual

„ BMOV

Block move Copy Block

Equation: BMOV(V1, V2, V3)

BMOV (V1, V2, V3) means to move data (number of word is A3) of data from address V2 to
address V1 in block. Data format is word. If the block length is more than internal memory or
max number of PLC register, there will be error when compiling.

Example:

Move the data in $0, $1, $2, $3, $4 to $10, $11, $12, $13 in order. Total the same 4 Words.

$0 = 1

$1 = 2

$2 = 3

$3 = 4

BMOV($10, $1, 4)

After executing BMOV command, $10=1, $11=2, $12=3, $13=4.

„ FILL

Fill the Memory

Equation: FILL(V1, V2, V3) [(Signed)]

FILL(V1, V2, V3) means to fill address V1 with data in address V2 and the data number is V3. If
the block length is more than internal memory or max number of PLC register, there will be
error when compiling.

Example:

$5 = 10

FILL($0, $5, 4)

Executing FILL command to fill $0, $1, $2, $3 with constant 10.

„ CHR

Convert Text to ASCII code

Equation: CHR(V1, "V2")

CHR(V1, "V2") means to convert text in address V2 to ASCII code and store in V1. The max
length is 128 words.

Example:

CHR($1, "AB12")

After executing CHR command, 4241H will be stored in $1 and 3130H will be stored in $2.

4-16 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

„ FMOV

Transfer Floating Point Data

Equation: V1 = FMOV(V2) (Signed DW)

Transfer floating point data from V2 to V1. No data change within V2 after executing FMOV
command.

Example:

Transfer constant 44.3 to the internal memory address $0.

$0 = FMOV(44.3) (Signed DW)

Transfer the same data of PLC 1@X0 to the internal memory address $0.

$0 = FMOV(1@X0) (Signed DW)

„ Data Conversion

Command Equation Description


BCD V1 = BCD(V2) Converts BIN Data into BCD
BIN V1 = BIN(V2) Decimal value conversion
W2D V1 = W2D(V2) Convert WORD to DWORD
B2W V1 = B2W(V2, V3) Convert BYTE to WORD
W2B V1 = W2B(V2, V3) Convert WORD to BYTE
SWAP SWAP (V1, V2, V3) Swap BYTE data
XCHG XCHG (V1, V2, V3) Exchange data
MAX V1 = MAX(V2, V3) Get Maximum value
MIN V1 = MIN(V2, V3) Get Minimum value
A2H V1 = A2H(V2) Convert ASCII code to 4-digit integer
H2A V1= H2A (V2) Convert hexadecimal integer to ASCII code
FCNV V1= FCNV (V2) Convert integer to floating point value
ICNV V1= ICNV (V2) Convert floating point value to integer

Table 4.3.4 Data conversion command table

„ BCD

Convert BIN Data into BCD value

Equation: V1 = BCD(V2) [(DW)]

The binary data in V2 is converted into BCD value, and stored in V1.

Example:

The binary data in $4 is 5564. After executing BCD command, the binary data in $4 is converted to
5564H.

$4 = 5564

$4 = BCD($4)

Revision 05/30/2006, EH00 4-17


Chapter 4 Macro Function|ScrEdit Software User Manual

„ BIN

Converts BCD Data into BIN value

Equation: V1 = BIN(V2) [(DW)]

The BCD data in V2 is converted into BCD value, and stored in V1.

Example:

The BCD (hexadecimal) data in $4 is 5564H. After executing BIN command, the BCD data in $4 is
converted to 5564.

$4 = 5564H

$4 = BIN($4)

„ W2D

Convert WORD to DWORD

Equation: V1 = W2D(V2) [Signed]

The WORD value in V2 is converted into DWORD value, and stored in V1.

Example:

The WORD value in decimal format in $4 is -7. After executing W2D command, the value in $7 is
converted to -7.

$4 = -7

$7 = W2D($4)(Signed)

„ B2W

Convert BYTE to WORD

Equation: V1 = B2W(V2, V3)

Convert BYTE data (number of byte is V3) from V2 to WORD value and store the result in V1.
The high byte will be filled with 0. In other words, that each word of V2 is two bytes. These two
bytes will be converted to two words and stored in V1.

Example:

Assume that the value of $65534 is 12. That means converting 12 BYTES (6 WORDS) to 12 WORDS
from $785 and store the result in $10 to $21.

$10=B2W($785, $65534)

„ W2B

Convert WORD to BYTE

Equation: V1 = W2B(V2, V3)

Convert WORD data (number of word is V3) from low-byte of V2 to BYTE format (discard high-
byte of V2) and store the result in V1.

4-18 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

Assume that the value of $985 is 12. It means to read 12 WORDS from low-byte of $986 and convert
these 12 WORDS to 12 BYTES (6 WORDS) and store the result in $65 to $70.

$65= W2B($986, $985)

„ SWAP

Swap BYTE Data

Equation: SWAP (V1, V2, V3)

Swap high-byte and low-byte of V2, V2+1, V2+2…V2+V3 (WORD) and store the result in the
starting position of V1, V1+1, V1+2…V1+V3 in order.

Example:

Swap the high-byte and low-byte of $10, $11, …, $14 and store the result in $1, $2, .., $5 in order.

SWAP($1, $10, 5)

If $11 = 1234H, after executing SWAP command, $2 = 3412H.

„ XCHG

Exchange Data

Equation: XCHG (V1, V2, V3)[(DW)]

Exchange the data of V2, V2+1, V2+2…V2+V3 and the data of V1, V1+1, V1+2.., V1+V3. The data
of V1 and V2 will be exchanged after executing XCHG command.

Example:

Exchange the data of $10, $11, …, $14 and the data of $1, $2, .., $5 in order.

XCHG($1, $10, 5)

If $11 = 1234H and $2 = 5678H, $2 = 1234H and $1 = 5678H after executing XCHG command.

„ MAX

Get Maximum Value

Equation: V1 = MAX(V2, V3)[ (Signed DW | DW)]

Get the maximum value from V2 and V3 and store the result in V1.

Example:

$0 = 0

$1 = 2

$2 =10

$0 = MAX($1, $2)

The result Æ $0 = 10

Revision 05/30/2006, EH00 4-19

You might also like