94
Between FOR~NEXT, CJ nesting is not allowed. FOR~NEXT must be in pairs in one STL.
Example 1: when M0 is ON, the FOR NEXT starts to sort the numbers in the range of D1 to
D20 from small to large. D21 is offset value. If there are many sortings in the program,
please use C language to save the programming time and scanning time.
SM2
MOV K19 D0
M0
FOR D0
MOV K0 D21
SM0
FOR D0
D1[D21] D2[D21]
XCH D1[D21] D2[D21]
INC D21
NEXT
NEXT
LD SM2 //SM2 is initial ON coil
MOV K19 D0 //the times of FOR loop
LD M0 //M0 to trigger the FOR loop
MCS //
FOR D0 //Nesting FOR loop, the loop times is D0
MOV K0 D21 //the offset starts from 0
LD SM0 //SM0 is always ON coil
MCS //
FOR D0 //nesting FOR loop, the loop times is D0
LD> D1[D21] D2[D21] //if the current data is larger than the next, it will be ON
tudonghoatoancau.com