10 External IO Devices
6.10.1 TKY instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
TKY | Ten key input | 16 | No | TKY S D1 D2 | 7 |
DTKY | 32 | No | 13 |
This instruction could read from 10 consecutive devices (S+0 to S+9) and will store an entered numeric string in device D1.
- S is the starting input port of pressing key, occupying the following ten bit units (such as X port);
- D1 is the storage unit for inputted value;
- D2 is the temp starting unit for state of current pressing key group, occupying the following eleven bit units;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | ||||||||||||
D1 | √ | √ | √ | √ | √ | √ | √ | √ | ||||||||
D2 | √ | √ | √ |
Program example
The corresponding hardware wiring is shown in below figure.
If user want to input "2013", just pressing key 2, 0, 1, 3 in order. The operation of PLC internal variable is shown as below figure. If using 32bit instruction (DTKY), and occupies 32bit variable. For the above case, they are D1, D0, which is higher word and lower word respectively.
TKY and DTKY instructions could only use one in the same program, set by parameters in an instruction, X0~X11 respectively correspond to numeric keys 0~9; M0~M9 correspond to the status of keys, key output unit will be reset whenever a key is pressed.
Key values are converted to BIN and saved to the designated D1 unit D; D0 will never change even when the power flow turns OFF.
When several keys are pressed simultaneously, the key which is firstly detected is valid; if the number entered is more than 4 digits, the first entered number will overflow and only a 4-digit number is left.
6.10.2 HKY instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
HKY | Hex key input | 16 | No | HKY S D1 D2 D3 | 9 |
DHKY | 32 | Yes | 17 |
This instruction creates a multiplex of 4 outputs (D1) and 4 inputs (S) to read in 16 different devices. Which are the decimal 0~9 keys and the functional keys of A~F. When the keys are pressed (ON), decimal numbers of 4 bits between 0~9999 or functional keys between A~F could be entered, depending on the sequence of the key press actions. If 32bit instructions are used, decimal numbers of 8 bits between 0~99,999,999 or functional keys between A~F could be entered.
HKY and DHKY instructions could only use one in the same program.
- S is the input port X of the keys, 4 X ports will be used;
- D1 is the starting port button of scouldning output Y port, and it uses the four Y ports.
- D2 is the storage unit for the entered values from the keys, with a range of 0~9999. If 32bit instructions are used, decimal numbers of 8 bits between 0~99,999,999 could be entered.
- D3 is the address which displays the entering status of the keys, which occupies a variable unit of 8 continuous bits;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | |||||||||||||||
D1 | √ | |||||||||||||||
D2 | √ | √ | √ | √ | √ | √ | ||||||||||
D3 | √ | √ | √ |
Program example
- MT transistor type controller should be used due to large delay in relay output;
- When driver power flow X20 turns OFF, D0 remains the same and M0~M7 become OFF;
- It takes 8 scouldning cycles to perform key scouldning. After that, M8029 will be set for 1 scouldning cycle;
When using this instruction, the scould period needs to be greater than or equal to the filter time of X0 ~ 7 input. There are two ways:
- Using a constant scould period, set the value of D8039 (unit ms) to be equal to or greater than the filtering time (D8020), and then turn M8039 ON;
- Add the REFF instruction before this instruction to set the REFF parameter to a value less than or equal to the scould period.
6.10.3 DSW instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
DSW | Digital Switch | 16 | No | DWS S D1 D2 n | 9 |
This instruction multiplexes 4 outputs (D1) through 1 or 2 sets of switches. Each set of switches consists of 4 thumb wheels providing a single digit input.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | |||||||||||||||
D1 | √ | |||||||||||||||
D2 | √ | √ | √ | √ | √ | |||||||||||
n | Constant, n=1~2 |
Program example
Perform the operation to scould and read the digit switches setting if X20=ON
- The setting values for the first set of digit switches are converted to BIN and saved to D0;
- The setting values for the second set of digit switches are converted to BIN and saved to D1;
- M8029 will be set for scouldning cycle after one-time reading is completed;
Note for use
- It is recommended that transistor output units are used with this instruction.
- A digital switch set to read operation requires multiple scould cycle to complete, if the use of keystrokes to start the read operation, it is recommended to use the following program to ensure the integrity of the readable cycle:
When using this instruction, the scould period needs to be greater than or equal to the filter time of X0 ~ 7 input. There are two ways:
- Using a constant scould period, set the value of D8039 (unit ms) to be equal to or greater than the filtering time (D8020), and then turn M8039 ON;
- Add the REFF instruction before this instruction to set the REFF parameter to a value less than or equal to the scould period.
6.10.4 SEGD instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
SEGD | Seven segment decoder | 16 | No | SEGD S D | 5 |
SEGDP | 16 | Yes | 5 |
A single hexadecimal digit occupying the lower 4 bits of source device S is decoded into a data format used to drive a seven segment display. A representation of the hex digit is then displayed. The decoded data is stored in the lower 8 bits of destination device D. The bit devices indicate:
- S: The source data remaining to be decoded (b0 to b3)
- D: The variable used to store the decoded data
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | √ | √ |
Program example
When X20 is triggered, a single hexadecimal digit occupying the lower 4 bits of D0 is decoded into a data format, and then output to Y10~Y17. The decoded format as below
6.10.5 SEGL instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
SEGL | Seven segment with latch | 16 | No | SEGL S D n | 7 |
SEGL uses 8 or 12 Y port to drive 4 bits or 8 bits seven-segment digital tube. Tube is display by scould PLC programming manual 4.
- S: The data to be displayed, it will not be displayed until the value is converted to BCD;
- D: The beginning number of the Y port that used to drive digital tube;
- n: The number of display groups, signal positive and negative logic, and other related set values;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | |||||||||||||||
n | Constant, n=0~7 |
Program example
Corresponding hardware connection is as follows. The contents of D0 are displayed in the first group of digital tube, the contents of D1 are displayed in the second group of digital tube and the procedure operation will run error when D0 or D1's numerical reading exceeds 9999:
The digital tubes in the wiring diagram come with the data show's latch, decoding and driving of 7 segment digital tube, negative logic type (the input data is considered as 1, or strobe when input port is low ) 7-segment digital display tubes. In the display processing, PLC's Y4 ~ Y7 port will automatically scould cycle and only one port is ON and as a bit strobe. In this moment, the data of Y0~Y3 port is the BCD code data sent to the corresponding bits and when bit strobe signal change from the ON → OFF, it will be latched to the latch of digital tube. The digital tubes will display the number after internal decoding and driving. PLC systems will deal with Y4 ~ Y7 cycle in turn and by the same process until all the 4 bits has been processed. Similarly, Y10 ~ Y13 is the second group data output port of 4-bit digital tubes and share Y4 ~ Y7 bit strobe line, so the process is in the same and both groups' display is processed at the same time. For the example, the first group will display 2468 and the second group willdisplay9753whenD0=K2468, D1=K9753.
The SEGL instruction takes 12 program scoulds to complete one output cycle regardless of the number of display sets used. On completion, the execution complete flag M8029 is set.
If there is one group has 4 digits, n=0~3.If there are two groups have 4 digits, n=4~7.
Displayed number | First group | Second group | ||||||
Polarity of Y output | PNP | NPN | PNP | NPN | ||||
Strobe and data polarity | Same | Opposite | Same | Opposite | Same | Opposite | Same | Opposite |
Value of n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
The SEGL instruction may be used TWICE on LX3V series PLC.
Note for use
- It is recommended that transistor output units are used with this instruction.
- This instruction is executed concurrently with the scould period (operation cycle) of the programmable controller. In order to perform a series of display, the scould cycle of PLC needs more than 10ms; when less than 10ms, using a constant scould mode, please make sure the scould cycle is more than 10ms to run regularly;
- The voltage of the transistor output of the programmable controller is about 1.5V;
6.10.6 ARWS instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
ARWS | Arrow Switch | 16 | No | ARWS S D1 D2 n | 7 |
This instruction displays the contents of a single data device D1 on a set of 4 digits, seven segment displays. The data within D1 is actually in a standard decimal format but is automatically converted to BCD for display on the seven segment units. Each digit of the displayed number could be selected and edited. The editing procedure directly changes the value of the device specified as D1.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | ||||||||||||
D1 | √ | √ | √ | √ | √ | |||||||||||
D2 | √ | |||||||||||||||
n | Constant, n=0~3 |
Program example
The corresponding hardware wiring is shown in the following figure, in which PLC is the transistor output type.
Operating procedures
- The tube shows a figure value of D0. Press X10~X13 to modify the value, which should be within the 0~9999 range;
- When the X20 is ON, the cursor digit is shown as kilobits. Each time the cursor right (X12) is pressed, the specified bit switches in the order of "thousand→hundred→ten→thousand"; When pressing the cursor left (X13), the switch order reverses; and the digit cursor is indicated by the LED which is connected with the gating pulse signal (Y004 ~Y007.
- The cursor digit number switches in the order of 0 → 1→ 2→……8→9→0→1 when the increment key (X11) is pressed, when pressing the decrement key (X10), the number switches in the order of 0→9→8→7→…… 1→0→9,and the modified value becomes operative at once.
Note for use
If the scould time of user program, please run in constant scould time or at a fixed time interval within a timed interrupt.
6.10.7 ASC instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
ASC | ASCII Code | 16 | No | ASC S D | 11 |
- S: The source data string, it consists of up to 8 characters taken from the printable ASCII character set;
- D: The start address to saved code. It occupies four (M8161=0) or eight(M8161=1) variable addresses;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | Only one, 8 character string may be entered at any one time. | |||||||||||||||
D | √ | √ | √ |
Program example
ASCII code table
Decimal | ASCII (Hex) | Decimal | ASCII (Hex) |
0 | 30 | 5 | 35 |
1 | 31 | 6 | 36 |
2 | 32 | 7 | 37 |
3 | 33 | 8 | 38 |
4 | 34 | 9 | 39 |
English letter | ASCII (Hex) | English letter | ASCII (Hex) |
A | 41 | N | 4E |
B | 42 | O | 4F |
C | 43 | P | 50 |
D | 44 | Q | 51 |
E | 45 | R | 52 |
F | 46 | S | 53 |
G | 47 | T | 54 |
H | 48 | U | 55 |
I | 49 | V | 56 |
J | 4A | W | 57 |
K | 4B | X | 58 |
L | 4C | Y | 59 |
M | 4D | Z | 5A |
Code | ASCII (Hex) | Code | ASCII (Hex) |
STX | 02 | ETX | 03 |
6.10.8 PR instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
PR | ASCII Code print | 16 | No | PR S D | 5 |
Source data (stored as ASCII values) is read byte by byte from the source data devices. Each byte is mapped directly to the first 8 consecutive destination devices D +0 to D +7). The final two destination bits provide a strobe signal (D +10, numbered in octal) and an execution/busy flag (D +11, in octal)
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | |||||||||||||
D | √ |
Program example
If the ASCII code in D200~D203 is "Stopped", the corresponding output port signal and its timing are shown below.
Note for use
- This instruction should only be used on transistor output PLC’s;
- The PR instruction will not automatically repeat its operation unless the drive input has been turned OFF and ON again;
- 16-byte operation requires the special auxiliary flag M8027 to be driven ON, unless 8-byte operation will be executed;
- Once the PR instruction is activated it will operate continuously until all 16 bytes of data have been sent or the value 00H (null) has been sent. M8029 the execution complete flag is set.
- If the scould time of user program, please run in constant scould time or at a fixed time interval within a timed interrupt.
6.10.9 FROM instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
FROM | Read data from BFM | 16 | No | FROM m1 m2 D n | 9 |
FROMP | 16 | Yes | 9 | ||
DFROM | 32 | No | 17 | ||
DFROMP | 32 | Yes | 17 |
The FROM instruction reads data from BFM of the special function block.
- m1: The special function block with the logical block position;
- m2: The BFM memory address;
- D: The start address for stored data;
- n: Data length;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
D | √ | √ | √ | √ | √ | √ | √ | √ | ||||||||
m1, m2= 0~32767; n=1~514(16-bit),1~257(32-bit); D= K1~K4 (16-bit) or K1~K8 (32-bit); m1, m2, n couldn’t support D device; |
Program example
When X0 is triggered, PLC reads data from BFM20 of #1 special function block, and stores data in D200, the data length is 1;
When using instructions in 32-bit, addresses designated by D are the low 16-bit addresses; addresses designated by D+1 are the high 16-bit addresses;
n means data length, in 16-bit mode, n=2 means 2 words, but in 32bit mode, n=1 means 2 words.
6.10.10 TO instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
TO | Write data to BFM | 16 | No | TO m1 m2 D n | 9 |
TOP | 16 | Yes | 9 | ||
DTO | 32 | No | 17 | ||
DTOP | 32 | Yes | 17 |
The TO instruction writes data to BFM of the special function block.
- m1: The special function block with the logical block position;
- m2: The BFM memory address;
- D: The start address for stored data;
- n: Data length;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
D | √ | √ | √ | √ | √ | √ | √ | √ | ||||||||
m1, m2= 0~32767; n=1~514(16-bit),1~257(32-bit); D= K1~K4 (16-bit) or K1~K8 (32-bit); m1, m2, n couldn’t support D device; |
Program example
When X1 is triggered, PLC writes data from D220 to BFM24 of #1 special function block, and stores, the data length is 1;
When using instructions in 32-bit, addresses designated by D are the low 16-bit addresses; addresses designated by D+1 are the high 16-bit addresses;
n means data length, in 16-bit mode, n=2 means 2 words, but in 32bit mode, n=1 means 2 words.
Points to note about FROM/TO instruction
Accessing the expansion module with the FROM/TO instruction is a time-consuming operation, so the scould cycle will be extended if there were many FROM/TO instructions. In order to prevent running timeout, users could add WDT instruction before FROM/TO, or stagger the execution time of the FROM/TO instruction, or using pulse type instruction.
6.10.11 GRY instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
GRY | Gray code conversion | 16 | No | GRY S D | 5 |
GRYP | 16 | Yes | 5 | ||
DGRY | 32 | No | 9 | ||
DGRYP | 32 | Yes | 9 |
The binary integer value in S is converted to the GRAY CODE equivalent and stored at D.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | √ | √ |
BIN → GRY Mathematical algorithm: from the right one, in turn, each bit do the XOR operation with the left bit (XOR), as the corresponding GRY bit of the value, the left one unchanged (equivalent to the left is 0);
Program example
[Result]:
6.10.12 GBIN instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
GBIN | Calculates the gray code value of an integer | 16 | No | GBIN S D | 5 |
GBINP | 16 | Yes | 5 | ||
DGBIN | 32 | No | 9 | ||
DGBINP | 32 | Yes | 9 |
The GRAY CODE value in S is converted to the normal binary equivalent and stored at D.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | √ | √ |
GRY → BIN Mathematical algorithm: from the left of the second place, each bit with the left side of a decoded value of XOR, as the bit after decoding the value (the left one is still the same).
Program example
[Result]