11 - 332 11 - 332
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Program Example
(1) Program example for a format 1 control table
100 'A program example that writes data nonsequentially to devices in a Q/QnA series PLC CPU’s
device memory
110 DIM TBL%(20),A%(10)
:
'Defines arrays
120 TBL%(0)=255
:
'Specifies the station number to
communicate with to the local station
130 TBL%(1)=516
:
'Specifies to write data nonsequentially to
the devices of the Q/QnA series PLC CPU
140 TBL%(2)=&H101
:
'Writes to one bit device point and one
word device point
150 TBL%(3)=&H1
:
'Writes to one double-word device point
160 TBL%(4)=168
:
'Specifies data registers (D)
170 D!=0
:
'Specifies device number 0
GOSUB 400
190 TBL%(5)=L%
:
'Stores the lower digit of the device number
200 TBL%(6)=H%
:
'Stores the higher digit of the device
number
210 TBL%(7)=0
:
'Specifies word units as processing unit
220 TBL%(8)=0
:
'Fixed value
230 TBL%(9)=144
:
'Specifies internal relays (M)
240 D!=0
:
'Specifies device number 0
250 GOSUB 400
260 TBL%(10)=L%
:
'Stores the lower digit of the device number
270 TBL%(11)=H%
:
'Stores the higher digit of the device
number
280 TBL%(12)=0
:
'Specifies bit units as processing unit
290 TBL%(13)=0
:
'Fixed value
300 TBL%(14)=168
:
'Specifies data registers (D)
310 D!=8000
:
'Specifies device number 8000
320 GOSUB 400
330 TBL%(15)=L%
:
Stores the lower digit of the device number
340 TBL%(16)=H%
:
'Stores the higher digit of the device
number
350 TBL%(17)=0
:
'Specifies double-word units as processing
unit
360 TBL%(18)=0
:
'Fixed value
370 A%(0)=100:A%(1)=200:A%(2)=300
:
'Specifies the values to write
380 PCRD TBL%( ),A%( )
:
'Executes the write operation
390 END
400 H!-INT(D!/65536!)
:
'Splits into lower and higher digits
410 L!=D!-H!*65536!
420 H$=RIGHT$(“0000”+HEX$(H!),4)
430 L$=RIGHT$(“0000”+HEX$(L!),4)
440 L%=VAL(“&H+L$)
450 H%=VAL(“&H”+H$)
460 RETURN