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=處理過后的模擬輸入值