0% found this document useful (0 votes)
34 views11 pages

Chapter 4 Macro Function - Scredit Software User Manual: Revision 05/30/2006, Eh00

This document summarizes macro functions in ScrEdit software including: 1) W2B converts words to bytes and stores the result. 2) SWAP, XCHG commands exchange or swap data between registers. 3) Comparison commands like IF...THEN evaluate conditions and allow conditional branching. 4) Flow control commands like GOTO, LABEL, FOR...NEXT allow program branching and looping.

Uploaded by

ryo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views11 pages

Chapter 4 Macro Function - Scredit Software User Manual: Revision 05/30/2006, Eh00

This document summarizes macro functions in ScrEdit software including: 1) W2B converts words to bytes and stores the result. 2) SWAP, XCHG commands exchange or swap data between registers. 3) Comparison commands like IF...THEN evaluate conditions and allow conditional branching. 4) Flow control commands like GOTO, LABEL, FOR...NEXT allow program branching and looping.

Uploaded by

ryo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

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


Chapter 4 Macro Function|ScrEdit Software User Manual

„ MIN

Get Minimum Value

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

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

Converts 4 ASCII code to a four digits integer in hexadecimal format

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)

After executing A2H command, the data in $1 will be converted to 4368H.

„ H2A

Converts four digits integer in hexadecimal format to 4 ASCII code

Equation: V1= H2A (V2)

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)

After executing H2A command, $10=0031H, $11=0032H, $12=0033H and $13=0034H.

4-20 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

„ FCNV

Convert integer to floating point value

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

Convert floating point value or integer in V2 to floating point value and store in V1.

Example:

$2 = 100

$1 = FCNV($2)(Signed DW)

The result Æ $1 = 100.0

„ ICNV

Convert floating point value to integer

Equation: V1= ICNV (V2)

Convert floating point value or integer in V2 to integer and store in V1.

Example:

FMOV($2, 100.5)

$1 = ICNV ($2)(Signed DW)

The result Æ $1 = 100

„ Comparison

„ IF…THEN GOTO LABEL …

Equation: IF expression THEN GOTO LABEL identifier

If the command of expression is true, then it will go to LABEL identifier perform the program.

Please refer to the following table for the command of expression.


Command Description Remark
V1 == V2 V1 is equal to V2
V1 != V2 V1 is not equal to V2
V1 > V2 V1 is greater than V2
V1 >= V2 V1 is greater than or equal to V2
V1 < V2 V1 is smaller than V2
V1<= V2 V1 is smaller than or equal to V2 V1 and V2 should be
Perform AND command on V1 andV2 internal memory or
V1 && V2 == 0 and the result of AND operation is equal constant.
to 0
Perform AND command on V1 andV2
V1 && V2 != 0 and the result of AND operation is not
equal to 0
V1== ON V1 is ON
V1== OFF V1 is OFF

Table 4.3.5 Comparison command table

Revision 05/30/2006, EH00 4-21


Chapter 4 Macro Function|ScrEdit Software User Manual

Example:

When $2 is greater than or equal to 10, it will go to LABEL 1 and continue to perform the program.

IF $2 >= 10 THEN GOTO LABEL 1

…..

LABEL 1

…..

Equation: IFB V1 == {ON | OFF} THEN GOTO LABEL identifier

If V1 is ON or OFF, it will go to LABEL identifier to perform the program. V1 is PLC address.

Example:

IFB 1@X0 == ON THEN GOTO LABEL 1

„ IF…THEN CALL …

Equation: IF V1 == V2 THEN CALL macro

If V1 is equal to V2, it will call macro. V1 and V2 should be internal memory or constant.

Example

If $2 is equal to 10, then it will cal sub-macro 1.

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 is smaller than 100, $1 = $1 + 1 is executed. Otherwise $1 = $1 + 10 is executed.

4-22 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

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.

Equation: GOTO LABEL V1

Go to the internal designated Label V1 in the program unconditionally.

Example:

Go to the position of designated Label 2 and continue to execute the program unconditionally.

GOTO LABEL 2

…..

LABEL 2

„ LABEL

Label such as Label V1

Equation: LABEL V1

Please notice that the label cannot be repeated in a Macro.

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

…..

Revision 05/30/2006, EH00 4-23


Chapter 4 Macro Function|ScrEdit Software User Manual

„ CALL..RET

Call Sub-macro program

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

After the operation, the result is $1 = 10, $10 = 2.

Please notice that the loop times will not change even the users reset the value within $10.

4-24 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

„ END

End the macro

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

Table 4.3.6 Bit setting command table

„ SETB

Sets specific bit to be ON.

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

The result Æ $0 = FFFFH

Revision 05/30/2006, EH00 4-25


Chapter 4 Macro Function|ScrEdit Software User Manual

„ CLRB

Sets specific bit to be OFF.

Equation: CLRB V1

Set V1 Bit to be OFF

Example:

Set a value of 0 to the 0 number of bit within the internal memory $0.

$0 = FFFFH

CLRB $0.0

The result Æ $0 = FFFEH

„ INVB

Sets specific bit to be inversed. ON Æ OFF, OFF Æ ON

Equation: INVB V1

Set V1 Bit to be inversed. ON Æ OFF, OFF Æ ON

Example:

Set a value of 0 to the 0 number of bit within the inversed internal memory $0.

$0 = FFFEH

INVB $0.0

The result Æ $0 = FFFFH

„ GETB

Get bit value

Equation: V1 = GETB V2

Get V2 Bit value and store in V1

Example:

Get the 3rd Bit value within $0 and store it to the 5th Bit within $10.

$2 = FFFEH

$10 = 0

$10.5 = GETB $0.3

The result Æ $10 = 4

4-26 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

„ Communication

Command Equation Description


INITCOM V1= INITCOM (V2) Initial setup COM port
ADDSUM V1=ADDSUM(V2, V3) Use addition to calculate checksum
XORSUM V1 = XORSUM(V2, V3) Use XOR to calculate checksum
PUTCHARS V1 = PUTCHARS(V2, V3, V4) Output characters by COM port
GETCHARS V1 = GETCHARS(V2, V3, V4) Get characters by COM port
SELECTCOM SELECTCOM(V1) Select COM port
CLEARCOMBUFFER CLEARCOMBUFFER(V1, V2) Clear COM port buffer
Calculate the length of texts and
CHRCHKSUM V1 = CHRCHKSUM(V2, V3, V4)
checksum

Table 4.3.7 Communication command table

„ INITCOM

INITCOM → Initial setup COM port to start communication and set communication protocol.

Fig. 4.3.2 INITCOM

Revision 05/30/2006, EH00 4-27


Chapter 4 Macro Function|ScrEdit Software User Manual

Fig. 4.3.3 Variable2 settings in INITCOM (communication protocol)

Fig. 4.3.4 COM port Fig. 4.3.5 Communication interface

Fig. 4.3.6 Data Bit Fig. 4.3.7 Parity bit

Fig. 4.3.8 Stop bit Fig. 4.3.9 Baud rate

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.

No Flow Control: Flow control function is disabled.

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.

4-28 Revision 05/30/2006, EH00


Chapter 4 Macro Function|ScrEdit Software User Manual

Fig. 4.3.10 Flow control

„ 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.

Fig. 4.3.11 ADDSUM

„ 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.

Fig. 4.3.12 XORSUM

Revision 05/30/2006, EH00 4-29

You might also like