自由口模式下PLC與計(jì)算機(jī)的通信
程序清單
主程序:
NETWORK 1
LDSM0.1//第一次掃描調(diào)用初始化子程序
CALLinitialize
NETWORK 2
LDB=VB134, VB199 //指令中的站地址與本機(jī)站地址相符
AB=VB102, 5//指令類型為讀指令
AM0.0//BCC碼校驗(yàn)正確
CALLRead//調(diào)用讀子程序
NETWORK 3
LDB=VB134, VB199//指令中的站地址與本機(jī)站地址相符
AB= VB102, 6//指令類型為寫指令
AM0.0//BCC碼校驗(yàn)正確
CALLWrite//調(diào)用寫子程序
NETWORK 4
LDM0.1//指令接收完成后調(diào)用BCC碼校驗(yàn)子程序
CALLVerify
NETWORK 5
LDSM4.5//當(dāng)端口空閑時啟動RCV
RCVVB100, 0
Read子程序:
NETWORK 1
LDSM0.0//停止端口0的接收
RSM87.7, 1
RM0.0, 1
RCVVB100, 0
NETWORK 2
LDSM0.0//將數(shù)據(jù)寫入發(fā)送緩沖區(qū)
MOVB 103, VB154
MOVB1, VB155
HTA*VD135, VB156, 16
MOVB26, VB174
MOVB21, VB153
NETWORK 3
LDSM0.0//計(jì)算BCC校驗(yàn)碼
FORVW177, +1, +16
NETWORK 4
LDSM0.0
XORB*VD181, VB180
NETWORK 5
LDSM0.0
INCDVD181
NETWORK 6
NEXT
NETWORK 7
LDSM0.0
HTAVB180, VB172, 2//BCC校驗(yàn)碼寫入發(fā)送緩沖區(qū)
NETWORK 8
LDSM4.5//發(fā)送反饋信息
XMTVB153, 0
Write子程序:
NETWORK 1
LDSM0.0//停止端口0的接收
RSM87.7, 1
RM0.0, 1
RCVVB100, 0
NETWORK 2
LDSM0.0//裝入要寫如數(shù)據(jù)源的地址指針
MOVD&VB115, VD145
NETWORK 3
LDSM0.0//寫入數(shù)據(jù)
ATH*VD145, *VD135, VB139
NETWORK 4
LDSM0.0//指令執(zhí)行的反饋信息寫入發(fā)送緩沖區(qū)
MOVB21, VB153
MOVB103, VB154
MOVB2, VB155
MOVB26, VB174
NETWORK 5
LDSM4.5//發(fā)送指令執(zhí)行的反饋信息
XMTVB153, 0
Verify子程序:
NETWORK 1
LDSM0.0
RM0.1, 1//復(fù)位verify子程序的執(zhí)行條件
NETWORK 2
LDSM0.0//計(jì)算BCC碼
FORVW175, +1, +29
NETWORK 3
LDSM0.0
XORB*VD149, VB179
NETWORK 4
LDSM0.0
INCDVD149
NETWORK 5
NEXT
NETWORK 6
LDB=VB179, VB140//當(dāng)BCC碼校驗(yàn)正確時,M0.0置1
AB=VB133, 71
SM0.0, 1
NETWORK 7
LDB=VB133, 71//BCC碼錯誤時發(fā)送反饋信息
AB《》VB179, VB140
MOVB21, VB153
MOVB103, VB154
MOVB3, VB155
MOVB26, VB174
RSM87.7, 1
RCVVB100, 0
XMTVB153, 0
NETWORK 8
LDB《》VB133, 71//指令格式錯誤或RCV超時時發(fā)送反饋信息
MOVB21, VB153
MOVB103, VB154
MOVB4, VB155
MOVB26, VB174
RSM87.7, 1
RCVVB100, 0
XMTVB153, 0
Initialize子程序:
NETWORK 1
LDSM0.0
MOVB9, SMB30//0口“9600,N,8,1”
NETWORK 2
LDSM0.0//RCV指令初始化
MOVB16#EC, SMB87
MOVB103, SMB88
MOVB71, SMB89
MOVB+1000, SMW92
MOVB35, SMB94
RSM87.2, 1
NETWORK 3
LDSM0.0
ATCHRCVcomplete, 23//連接口0接收完成的中斷
NETWORK 4
LDSM0.0
ATCHXMTcomplete, 9//連接口0發(fā)送完成的中斷
NETWORK 5
LDSM0.0
ENI //中斷允許
NETWORK 6
LDSM0.0
MOVB2, VB199//將本機(jī)站地址裝入寄存器
NETWORK 7
LDSM0.0
MOVB&VB102, VD149//裝入地址指針
MOVB0, VB179//BCC碼寄存器清零
MOVB&VB156, VD181//裝入地址指針
MOVB0, VB180//BCC碼寄存器清零
RCVcomplete中斷程序
NETWORK 1
LDSM0.0
ATHVB103, VB134, 2//指令譯碼(ASCII碼到十六進(jìn)制)
ATHVB105, VB135, 8
ATHVB113, VB139, 2
ATHVB131, VB140, 2
SM0.1, 1//置位Verify子程序的觸發(fā)條件
MOVB0, VB179//BCC碼寄存器清零
MOVD&VB102, VD149//裝入地址指針
XMTcomplete中斷程序
NETWORK 1
LDSM0.0
RM0.0, 1//復(fù)位BCC校驗(yàn)碼正確的標(biāo)志位
SSM87.7, 1//允許口0進(jìn)行接收
MOVB0, VB179//BCC校驗(yàn)碼寄存器清零
MOVB0, VB180//BCC校驗(yàn)碼寄存器清零
MOVD&VB102, VD149//重新裝入地址指針
MOVD&VB156, VD181
MOVB0, VB133 //接收緩沖區(qū)中存放指令結(jié)束字符的字節(jié)清零