IN
DB_no Int
DB_addr_begin int
Degree int
Piw_addr int
Time_base bool
out
Average int
inout
Mid int
result dint
temp
temp1 word
temp2 dword
temp3 dword
temp4 dint
temp5 dint
temp6 word
temp7 dword
temp8 word
temp9 dword
temp10 int
temp11 dword
temp12 dint
//平均值结果为result为Dint
//Time_base采用CPU clock Memory,时间越长,平均值结果越慢,控制的实时性越慢。
//采样资料Degree次数越多,平均值结果越慢,控制的实时性越慢。
L #DB_no //打开DB块
OPN DB [#temp1]
L #DB_addr_begin //找到DB块存储区的开始
SLD 3
T #temp2
A #Time_base //时基到,采集数据
JCN end
L #Mid
L 1
+I
T #Mid
L #Mid
L #Degree
>=I
JC a1 //采集次数未到,继续采集;采集完成,程序跳转到a1
L #Mid
L 4
*I
SLD 3
L #temp2
+D
T #temp3
L #Piw_addr
ITD
T DBD [#temp3]
JU end
a1: L #temp2 // 求最大值
LAR1
L DBD [AR1,P#0.0]
T #temp4
L #Degree
max: T #temp6
L #Degree
L #temp6
-I
L 4
*I
SLD 3
L #temp2
+D
T #temp7
L #temp4
L DBD [#temp7]
>D
JC a2
L DBD [#temp7]
T #temp4
a2: L #temp6
LOOP max
L #temp2 //求最小值
LAR1
L DBD [AR1,P#0.0]
T #temp5
min: T #temp8
L #Degree
L #temp8
-I
L 4
*I
SLD 3
L #temp2
+D
T #temp9
L DBD [#temp9]
L #temp5
>D
JC a3
L DBD [#temp9]
T #temp5
a3: L #temp8
LOOP min //求和
L 0
T #temp12
L #Degree
sum: T #temp10
L #Degree
L #temp10
L 4
*I
SLD 3
L #temp2
+D
T #temp11
L #temp12
L DBD [#temp11]
+D
T #temp12
L #temp10
LOOP sum
L #temp12
L #temp4 //减去最大值
-D
T #temp12
L #temp12
L #temp5 //减去最小值
-D
T #temp12
L #temp12
L #Degree
DEC 1
DEC 1
ITD
/D
T #result
L #result
T #Average //输出平均值结果
L -1
T #Mid
L #Degree
init: T #temp10 //初始化
L #Degree
L #temp10
-I
L 4
*I
SLD 3
L #temp2
+D
T #temp11
L #temp12
L DBD [#temp11]
+D
T #temp12
L #temp10
LOOP init
end: NOP 0
如上一份资料里的程序,输入后不正常。谢谢大家指点!!