Sie sind auf Seite 1von 2

Top

Contact Us

Back

VOL. 11

Word shifting

Example

Storing the stop duration of equipment in memory as history

Outline
The stop duration of equipment is measured using the internal timer of the KV, and is stored into data memory
DM0000. When the equipment stops again, the previous stop duration is transferred to DM0001 and the current
stop duration is written into DM0000. The last 5 stop durations are stored.

Example:
When stop 1 (1 min), stop 2 (2 min and 28 sec), and stop 3 (51 sec) are input sequentially, the contents of each
data memory is changed, as follows, each time a new stop duration is input.
Stop 1 (1 min)

#00060

DM0000:

Stop 3 (51 sec)

Stop 2 (2 min and 28 sec)

DM0001:

#00148

#00051

#00060

#00148
#00060

DM0002

DM0004

Programming Technique
Use the FOR-NEXT instructions and indirect addressing of data memory.
Use the LDA instruction and STA instruction to shift words in the data memory. The content of each data memory is
transferred as follows:
(4)

(5)
DM0000
Latest stop duration

(3)
DM0001

(2)
DM0002

(1)
DM0003

DM0004

(1): Content of DM0003 is transferred to DM0004.


(2): Content of DM0002 is transferred to DM0003.
(3): Content of DM0001 is transferred to DM0002.
(4): Content of DM0000 is transferred to DM0001.
(5): Latest stop duration is transferred to DM0000.

Indirect addressing of the data memory (format: #TMxx) can be performed using temporary data memory (such as TM10 and TM11).
Destination indirectly
Destination indirectly
Value of TM10
addressed by #TM10
addressed by #TM11
DM0003
#00004
DM0004

Word shifting

Value of TM10

(1)

#00003

(2)

#00002

DM0002

#00003

DM0003

(3)

#00001

DM0001

#00002

DM0002

(4)

#00000

DM0000

#00001

DM0001

When word shifting (1) is performed, for example, #00003 and #0004 are specified respectively for TM10 and TM11
to transfer data from #TM10 to #TM11 using the LDA instruction and STA instruction.
Word shifting of (1) to (4): Transfer from #TM10 to #TM11 is repeated using the FOR-NEXT instructions.
To use the FOR-NEXT instructions in combination with indirect addressing of data memory, refer to examples 1 and 2 of
FOR-NEXT applications of the visual KV Series Users Manual, Indirect addressing on page 521.

Top

Back

Contact Us

VOL. 11 Word shifting


Programming Example
1001
SET

0000
0001
0002

1000

0004

#65535
T000

1001

0003

1000
DIFD

T000
LDA

TM04
STA

#65535
LDA

TM04
SUB

1001
RES

TM05
STA

00
CALL

1000

At the rising edge of input to 0000, subroutine


program is called.

END

0005

SBN
00

0006
#00003
LDA

2002
0007

TM02
STA

2002

#TM02
LDA

#TM03
STA

Subroutine for executing word shifting

TM03
STA

To execute word shifting (1) first, DM0003 and


DM0004 are specified using TM02 and TM03.

FOR
#00004

Program between FOR and NEXT is repeated


4 times.
Content of the data memory indirectlyaddressed by TM02 is transferred to the data
memory indirectly-addressed by TM03. Then,
the value of TM02 and that of TM03 are
decremented respectively by one, and data
memory No. for the next word shifting is
specified.

#00004
LDA

0008
0009

ON duration of input 0000 is stored into


temporary data memory TM05.

TM02
DEC

TM03
DEC
NEXT

0010
0011

TM05
LDA

2002

#TM03
STA
RET

0012

Tips

After execution of program between FOR


and NEXT is terminated, the latest stop
duration is transferred to the data memory
(DM0000) indirectly-addressed by TM03.
If indirect addressing of data memory using temporary data memory is not used for the
above programming, program for word shifting (for which LDA instruction and STA instruction
are used) is shown below.
1001
SET

0000
1001
1000

1000
DIFD
#65535
T000

T000
LDA

TM04
STA

#65535
LDA

1000

TM04
SUB

TM05
STA

1001
RES

DM0003 DM0004
LDA
STA

Word shifting (1) is executed.

DM0002 DM0003
LDA
STA

Word shifting (2) is executed.

DM0001 DM0002
LDA
STA

Word shifting (3) is executed.

DM0000 DM0001
LDA
STA

Word shifting (4) is executed.

TM05 DM0000
LDA
STA

Word shifting (5) is executed.

Just change this value!

If word shifting is executed 20


times using the LDA instruction
and STA instruction, program
becomes longer as frequency
of execution increases.

FOR
#00004

When indirect addressing is used, what you have


to do is just to change the value of operand for the
FOR instruction. The program does not become
longer.

Das könnte Ihnen auch gefallen