4.3 Macro Operation: Keypad
4.3 Macro Operation: Keypad
4.3 Macro Operation: Keypad
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.
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.
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.
Bit data.
FMUL V1=FMUL(V2, V3) Multiplication
FDIV V1=FDIV(V2, V3) Division
FMOD V1=FMOD(V2, V3) Get Remainder
+, FADD
Addition
Perform the addition on V2 and V3, and store the addition result in V1.
Example:
$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)
-, FSUB
Subtraction
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
Perform the multiplication of V2 and V3, and store the multiplication result in V1.
Example:
$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)
/, FDIV
Division
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
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)
ADDSUMW
Repeated Addition
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
| 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
&& Operand
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
^ Operand
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
NOT
Perform the logical NOT operation on V2 and V3 and save the result of this calculation in V1.
Example:
$2 = F100H
$4 = NOT $2
<< Operand
Shift V2 (WORD/DWORD) data to left (number of bit is V3). The result of this calculation is
stored in V1.
Example:
$2 = F100H
$2 = $2 << 4
>> Operand
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
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
= Operand
Transfer data
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
BMOV
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)
FILL
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
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.
FMOV
Transfer floating point data from V2 to V1. No data change within V2 after executing FMOV
command.
Example:
Transfer the same data of PLC 1@X0 to the internal memory address $0.
Data Conversion
BCD
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)
BIN
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
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 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 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.
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.
SWAP
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)
XCHG
Exchange Data
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 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