例如输出6个随机数分别送到 MD0,MD4,MD8,MD12,MD16,MD20。主要想熟悉一下循环自加LOOP,和地址指针。
最佳答案
随机数没有真正的随机数,只有伪随机数。
指针用法:
FUNCTION "NS_aver_sum_deta" : VOID
TITLE =
VERSION : 0.1
VAR_INPUT
db_no : POINTER ;
pv : REAL ; //测量信号
END_VAR
VAR_TEMP
temp_ar1 : DWORD ; //地址寄存器
temp_ar2 : DWORD ;
ar1data1 : DWORD ; //前一个数地址
ar1data2 : DWORD ; //后一个数地址
ar1data3 : DWORD ; //第一个数地址
DB_ID : WORD ;
ZQP_SUM : REAL ;
count : DWORD ;
END_VAR
BEGIN
NETWORK
TITLE =
//初始化
TAR1 #temp_ar1;
TAR2 #temp_ar2;
L P##db_no;
LAR1 ;
L W [AR1,P#0.0];
T #DB_ID;
OPN DB [#DB_ID];
LAR1 P#26.0;
TAR1 #ar1data1;
+AR1 P#4.0;
TAR1 #ar1data2;
NETWORK
TITLE =
//写数据
L DBW 24;
_0a1: T DBW 22;
L DBD [#ar1data2];
T DBD [#ar1data1];
LAR1 #ar1data1;
+AR1 P#4.0;
TAR1 #ar1data1;
+AR1 P#4.0;
TAR1 #ar1data2;
L DBW 22;
LOOP _0a1;
L #pv;
T DBD [#ar1data1];
L DBD 26;
-R ;
T DBD 4; //deta
NETWORK
TITLE =
//初始化数据计算
L 0.000000e+000;
T #ZQP_SUM;
NETWORK
TITLE =
//初始化指针
TAR1 #temp_ar1;
TAR2 #temp_ar2;
LAR1 P#26.0;
TAR1 #ar1data1;
+AR1 P#4.0;
TAR1 #ar1data2;
NETWORK
TITLE =
//数据累计
L DBW 24;
_0a4: T DBW 22;
L DBD [#ar1data1];
L #ZQP_SUM;
+R ;
T #ZQP_SUM;
LAR1 #ar1data1;
+AR1 P#4.0;
TAR1 #ar1data1;
+AR1 P#4.0;
TAR1 #ar1data2;
L DBW 22;
LOOP _0a4;
L #ZQP_SUM;
T DBD 8;
L DBW 24;
ITD ;
DTR ;
/R ;
T DBD 0;
NETWORK
TITLE =
LAR1 #temp_ar1;
LAR2 #temp_ar2;
NETWORK
TITLE =
SET ;
SAVE ;
BEU ;
END_FUNCTION
图片说明:
提问者对于答案的评价:
xiexie
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc204558.html