Chapter 4 Macro Function - Scredit Software User Manual: Revision 05/30/2006, Eh00
Chapter 4 Macro Function - Scredit Software User Manual: Revision 05/30/2006, Eh00
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
MIN
Get the minimum value from V2 and V3 and store the result in V1.
Example:
$0 = 0
$1 = 2
$2 =10
$0 = MIN($1, $2)
The result Æ $0 = 2
A2H
Equation: V1 = A2H(V2)
Convert the ASCII code of V2 (4 WORDS) to integer and store the result in V1.
Example:
$10 = 0034H
$11 = 0033H
$12 = 0036H
$13 = 0038H
$1 = A2H($10)
H2A
Convert V2 (1 WORD in hexadecimal format) to the ASCII (4 WORDS) code and store the result
in V1.
Example:
$2 = 1234H
$10 = H2A($2)
FCNV
Convert floating point value or integer in V2 to floating point value and store in V1.
Example:
$2 = 100
$1 = FCNV($2)(Signed DW)
ICNV
Example:
FMOV($2, 100.5)
Comparison
If the command of expression is true, then it will go to LABEL identifier perform the program.
Example:
When $2 is greater than or equal to 10, it will go to LABEL 1 and continue to perform the program.
…..
LABEL 1
…..
Example:
IF…THEN CALL …
If V1 is equal to V2, it will call macro. V1 and V2 should be internal memory or constant.
Example
IF 10 = $2 THEN CALL 1
IF…ELSE…ENDIF
Equation:
IF expression1
Statement1
ELSEIF expression2
Statement2
ELSE
Statement3
ENDIF
This is logical determination from multiple conditions. If expression1 is true, Statement1 will be
executed. If expression1 is false, it will run expression2. If expression 2 is true, Stemenent2 will be
executed. If both expression 1 and expression 2 are false, Statement3 will be executed.
For the command of expression, please refer to table 4.3.5 (Comparison command table).
Example
IF $1 < 100
$1 = $1 + 1
ELSE
$1 = $1 + 10
ENDIF
Flow Control
There are five types for flow control: GOTO, LABEL, CALL..RET, FOR…NEXT and END.
GOTO
Unconditionally go to a specific Label. GOTO command will jump to designated label like Label V1
unconditionally.
Example:
Go to the position of designated Label 2 and continue to execute the program unconditionally.
GOTO LABEL 2
…..
LABEL 2
LABEL
Equation: LABEL V1
Example:
Go to the position of designated Label 2 and continue to execute the program unconditionally.
GOTO LABEL 2
…..
LABEL 2
…..
The Label 2 is repeated. An error will occur at this time to warn the users to indicate it is illegal.
LABEL 2
…..
CALL..RET
Equation: CALL V1
V1 represents the sub-macro number. The sub-macro number could be 001 ~ 512 and V1 should be
internal memory address or constant.
CALL
The rights of macro control will be transferred to sub-macro after
CALL V1 command is executed. V1 needs to return through RET
Main Sub-Macro
Macro A1
command. RET command will transfer the rights of macro control
to the next command of CALL command. The sub-macro number
could be 001 ~ 512 and the users also can name it freely. In the
RET
sub-macro program, the users also can CALL another sub-macro
Fig. 4.3.1 but the levels for CALL sub-macro should be less than 6 levels
due to memory limit and also for avoiding unexpected error.
FOR…NEXT
Program Loop
Equation:
FOR V1
Statement
NEXT
It is for nested loops. ”FOR” is the start of loop and ”NEXT” is the end of loop. The nested loop can up
to 5 levels max. V1 can be the internal memory or constant. When this command is executed, the
number of V1 Statement will be executed continuously. Statement is the combination of a section of
macro commands and also can be within the nested loop. The users can change V1 value through
command, but the number of times cannot be changed.
Example:
$10 = 10
$1 = 0
FOR $10
$1 = $1 + 1
$10 = 2
NEXT
Please notice that the loop times will not change even the users reset the value within $10.
END
Equation:
Statemenets1
END
Statements2
End command is used to end the macro program. Statements2 will not be executed after Statemenets1
is executed. The program will execute from the command of the first line next time. Please notice that
END means finishing executing macro. If END command is used in sub-macro, it indicates the program
is end here.
Example:
$1 = 10
$1 = $1 + 1
END
$1 = $1 + 1
After the operation, the result is $1 = 11, not $1 = 12 as the END command has ended the macro
program.
Bit Setting
There are four settings for BIT settings: SETB, CLRBL, INVB and GETB.
Command Equation Description
SETB SETB V1 Set V1 Bit to be ON
CLRBL CLRB V1 Set V1 Bit to be OFF
INVB INVB V1 Set V1 Bit to be inversed
GETB V1 = GETB V2 Get V2 Bit value and store in V1
SETB
Equation: SETB V1
Set V1 Bit to be ON
Example:
Set a value of 0 to the 0 number of bit within the internal memory $0.
$0 = FFFEH
SETB $0.0
CLRB
Equation: CLRB V1
Example:
Set a value of 0 to the 0 number of bit within the internal memory $0.
$0 = FFFFH
CLRB $0.0
INVB
Equation: INVB V1
Example:
Set a value of 0 to the 0 number of bit within the inversed internal memory $0.
$0 = FFFEH
INVB $0.0
GETB
Equation: V1 = GETB V2
Example:
Get the 3rd Bit value within $0 and store it to the 5th Bit within $10.
$2 = FFFEH
$10 = 0
Communication
INITCOM
INITCOM → Initial setup COM port to start communication and set communication protocol.
Flow Control: The transmission speed and communication validity are enhanced during
communication due to new transmission technology, such as compress immediately, debug,…etc. But
the new technology also makes the transmission speed between HMI and PC will longer than the
actual transmission speed. Therefore, ensure the data security and transmit complete data between
computer and HMI, the flow control is necessary.
CTS/RTS: It is flow control for hardware. It uses handshaking signal to control receiving and sending
data. The control is achieved via internal modem or external modem that connect to HMI by connecting
cable.
DSR/DTR: It is flow control for hardware also. It is used when PC and HMI is connected by cable
directly.
XON/XOFF: It is flow control for software. It is only used for 2400bps modem. The control method is to
generate control code by software and add it in the transmission data.
ADDSUM
ADDSUM → It uses addition to calculate checksum. V1=ADDSUM(V2, V3). V1 is the value after
calculation, V2 is the starting address for calculation and V3 is data length.
XORSUM
XORSUM → It uses XOR to calculate checksum. V1=XORSUM (V2, V3) V1 is the value after
calculation, V2 is the starting address for calculation and V3 is data length.