To add up all values in D0~D9 and store the result into the D10.
If you want to get the result of the sum (D0~D99) at the D100 instead in the above program, only need to change the
K10 in FOR K10 to K100.
The sprinkler system sets different opening and closing times from Sundays to Saturdays. The following example
uses the set ON time at D0~D13 and the set OFF time at D20~D33 to drive the sprinkler motor by the output Y0.
The time data of the Real-Time Clock (RTC) is compared with the setting value of the time schedule to determine the
ON / OFF of the sprinkler motor.
Hr. Min.
D1
D0
D3
D2
D5
D4
D7
D6
D9 D8
D11
D10
D13 D12
D21
D20
D23
D22
D25
D24
D27
D26
D29 D28
D31
D30
D33 D32
Set ON time Set OFF time
The simple program above can achieve the requirement easily, isn't it? In fact, dealing with a large number of regular
data, the most important thing is to select an appropriate data structure (method for data storage). Then, with the
characteristics of the index register, you can compile efficient programs.
RST
FOR K10
D100
M9000
M9000
RST
ADD D0V1 D100 D100
INC V1
NEXT
V1
Reset the content of V1 to zero
Reset D100 to zero, this component is to store the result
Assign to execute 10 times within the loop, that for every command between the For
and Next instructions.
The value of D0V1 is accumulated to the D100 once at each cycle.
Add 1 to the value of V1, and point to the next value to be accumulated.
End of the FOR~NEXT loop
The time data of RTC:
D9019 0(Sun.)~6(Sat.)
D9014
Minute
D9015
Hour
M9000
Double the day of a week from the RTC and put the
result to the Z0, that becomes the index for the time
comparison
ADD D9 0 19 D 9 0 1 9 Z0
D= D9 0 1 4 D 0 Z 0
Compare with the “Set ON time” to drive the Y0 ON.
SET Y 0
Compare with the “Set OFF time” to drive the Y0 OFF.
RST Y 0
D= D9 0 1 4 D 2 0 Z 0
34
Hr. Min.
Sun.
Mon.
Tue.
Wed.
Thu.
Fri.
Sat.