FC237块:用于处理Interbus总线上的4~20mA,0~10V模拟量信号
L #PW //int:IW22:22=10110
T MW 800 //10110
//;
L #P_Q //word
L 'Q ' //字符型
<>I //ACCU2=#P_Q,ACCU1='Q'
JC M001 //if ACCU2=ACCU1则执行下列程序,否则跳到M001
//;
T #conv_akku1 //Dword,值='Q'
L STW //装载状态字内容到ACCU1
T #conv_stw //装入ACCU1内容
L MB 801 //ACCU1=0000 0000 0001 0110=22
SLW 3 //ACCU1=0000 0000 1011 0000=176
LAR1 //AR1=0000 0000 0000 0000 0000 0000 1011 0000 32位指针=P#22.0
L #conv_stw //原状态字内容装入ACCU1
T STW //装入现在状态字
L #conv_akku1 //'Q'装入ACCU1
L IW [AR1,P#0.0] // PIW [AR1,P#0.0]:IW22值装入ACCU1
JU M002 //无条件跳到M002
//;
M001: NOP 0
T #conv_akku1 //Dword,值='Q'
L STW //装载状态字内容到ACCU1
T #conv_stw //装入ACCU1内容
L MB 801 //ACCU1=0000 0000 0001 0110=22
SLW 3 //ACCU1=0000 0000 1011 0000=176
LAR1 //AR1=0000 0000 0000 0000 0000 0000 1011 0000 32位指针=P#22.0
L #conv_stw //原状态字内容装入ACCU1
T STW //装入现在状态字
L #conv_akku1 //'Q'装入ACCU1
L IW [AR1,P#0.0] // PIW [AR1,P#0.0]:IW22值装入ACCU1
//;
M002: T MW 802 //IW22
//;
L #KT_I //Int=2
L 0
==I
JC M003
//;
L #KT_I
L 1
==I
JC M004
//;
L #KT_I
L 2
==I
JC M005
//;
L #KT_I
L 3
==I
JC M006
//;
L #KT_I
L 4
==I
JC M007
//;
//;
JU M008
//;
M003: AN M 802.7 //MW802=IW22,if最高位(符号位)为0跳到M009
JC M009
L 0 //if IW22最高位为"1"=负数,则清零数据块DB201之数据字:D_101
T #XA
JU M008 //无条件跳到M008
//;
//;
//;
M009: L #OGR //4500.0
L #UGR //0.0
-R //ACCU2-ACCU1=4500.0-0.0,结果存入ACCU1
L 3.276700e+004 //3.2767x10000=32767.0装入ACCU1
/R // 4500.0/32767.0=0.13733329264198736533707693716239,结果存于ACCU1
L MW 802 //IW22值装入ACCU1
DTR //转换双整数为浮点数,结果存入ACCU1
*R //ACCU2*ACCU1=0.1373333*IW22结果存入ACCU1
L #UGR //0.0装入ACCU1
+R //ACCU2+ACCU1,结果存入ACCU1
RND //ACCU1浮点数转换为双整数,结果存入ACCU1
T #XA //ACCU1值传送到DB201之数据字D_101
JU M008 //无条件跳到M008
//;
M004: L MW 802
T MD 804
AN M 802.7
JC M010
//;
L MD 804
+ L#-65536
T MD 804
//;
M010: L #OGR
L #UGR
-R
T MD 810
L MD 804
DTR
L 3.276700e+004
+R
L MD 810
*R
L 6.553400e+004
/R
L #UGR
+R
RND
T #XA
JU M008
//;
M007: R #_FB
AN M 803.1
JC M005
L #UGR
RND
T #XA
A M 803.1
= #_FB
JU M008
//;
// L 4.096000e+003
//;
//;
M005: L #OGR //4500.0
L #UGR //0.0
-R //ACCU2-ACCU1=4500.0-0.0,结果存入ACCU1
L 4.096000e+003 //4096.0装入ACCU1
/R // 4500.0/4096.0=1.0986328125,结果存于ACCU1
L MW 802 //IW22值装入ACCU1,例如: IW22=17364=0100 0011 1101 0100;IW=980=0000 0011 1101 0100
SRW 3 //ACCU1-L(低字)右移3位结果存入ACCU1 =0000 1000 0111 1010=2170; =0000 0000 0111 1010=122
DTR //ACCU1双字整数转换为浮点数,结果存入ACCU1
*R //ACCU2*ACCU1=2170.0(122.0)*1.0986328125,结果存入ACCU1
L #UGR //0.0装入ACCU1
+R //122.0+0.0
RND //浮点数转换为双整数
T #XA //模拟值装入数据块DB201字D_101
JU M008 //无条件跳到M008
//;
M006: L #OGR
L #UGR
-R
T MD 810
L MW 802
SRW 3
DTR
L 8.192001e+002
-R
T MD 802
AN M 803.7
JC M011
L #UGR
RND
T #XA
JU M008
//;
M011: L MD 810
L MD 802
*R
L 3.276800e+003
/R
L #UGR
+R
RND
T #XA
JU M008
M008: NOP 0
FC181上调用FC237块,读出各模拟量输入地址的实际值,非常准确
CALL FC 237
PW :=192
KT_I:=2
OGR :=1.000000e+003
UGR :=0.000000e+000
P_Q :=MW902
XA :=DB200.DBW2
_FB :=M905.0
NOP 0
CALL FC 237
PW :=168
KT_I:=2
OGR :=1.000000e+003
UGR :=0.000000e+000
P_Q :=MW902
XA :=DB200.DBW4
_FB :=M905.0
NOP 0
CALL FC 237
PW :=196
KT_I:=2
OGR :=1.000000e+003
UGR :=0.000000e+000
P_Q :=MW902
XA :=DB200.DBW6
_FB :=M905.0
NOP 0
CALL FC 237
PW :=216
KT_I:=2
OGR :=6.750000e+002
UGR :=5.000000e+001
P_Q :=MW902
XA :=DB200.DBW26
_FB :=M905.0
NOP 0
注:PW=模拟量输入地址;XA=处理过后的模拟输入值