<font face="Times New Roman"> ORG 1000H
GOTO MAIN
ORG 1080H
MAIN:
CALL T300MS
CALL INITE
GOTO MAIN
;***************
T300MS:
LDBR R30,0X00,1
LDBR R31,0X64,1
LDBR R32,0X00,1
LDBR R33,0X96,1
LDBR R34,0X00,1
LDBR R35,0XFA,1
LDBR R36,0X01,1
LDBR R37,0X2C,1
MOVDR 37,R25,2
JU R25,R30,T300_END
LDBR R80,1,1
JU R25,R32,T300_END
LDBR R80,2,1
JU R25,R34,T300_END
LDBR R80,3,1
JU R25,R36,T300_END
LDBR R80,4,1
LDBR R200,0,1
LDWR R25,0
MOVRD R25,37,2
NOP
RET
T300_END:
NOP
RET
;***************
;上电初始化
INITE:
IJNE R255,0,INIRET
LDBR R255,1,1
COMSET 40H,1632 ;设置串口4,波特率9600,上电执行一次
CONFIG 1,2,1
RET
; LDBR R250,0,1
; NOP
INIRET:
IJNE R80,1,NT1
CALL RDY04
RET
NT1:
IJNE R80,2,NT2
RET
NT2: IJNE R80,4,NT3
RET
NT3: ;IJNE R81,1,NTRET
CALL T1017
CALL T1018
NTRET: RET
RDY04:
IJNE R200,1,SENDR
IJNE R201,0,OT_RET
RDXLEN 4,R40 ;FIFO长度
IJNE R40,0,OT_TEST ;FIFO长度不等于0
RET
SENDR: ;读Y0~Y4状态
LDBR R90,0x01,1
LDBR R91,0x03,1 ;命令码
LDBR R92,0x00,1
LDBR R93,0x01,1
LDBR R94,0x00,1
LDBR R95,0x0A,1
LDBR R11,0x06,1
CRCA R90,R122,R11 ;6字节做ANSI CRC计算
MOV R122,R96,2 ;赋值给R96 R97
LDBR R9,0x08,1
COMTXD 4,R90,R9
LDBR R200,1,1
LDBR R201,0,1
RET
OT_TEST:
MOVDR 17,R41,1
IJNE R41,0,OT_RET
RDXLEN 4,R40
RDXDAT 4,R150,R40
IJNE R150,0X01,OT_RET
IJNE R151,0X03,OT_RET
IJNE R152,0X14,OT_RET
CALL SC3
CALL SC4
LDBR R201,1,1
RET
OT_RET:
NOP
RET
SC3:
LDBR R0,0X10,1
LDBR R1,0X17,1
LDBR R60,0X01,1
AND R60,R172,1
IJNE R60,0X01,SC30
LDBR R20,0,1
LDBR R21,1,1
MOVXR R20,0,1 ;写0x0001进变量
LDBR R244,0,1
LDBR R243,1,1
RET
SC30:
LDBR R20,0,1
LDBR R21,0,1
MOVXR R20,0,1 ;写0x0000进变量
LDBR R244,1,1
LDBR R243,0,1
RET
SC4:
LDBR R0,0X10,1
LDBR R1,0X18,1
LDBR R60,0X01,1
AND R60,R154,1
IJNE R60,0X01,SC40
LDBR R20,0,1
LDBR R21,1,1
MOVXR R20,0,1 ;写0x0001进变量
LDBR R242,0,1
LDBR R241,1,1
RET
SC40:
LDBR R20,0,1
LDBR R21,0,1
MOVXR R20,0,1 ;写0x0000进变量
LDBR R242,1,1
LDBR R241,0,1
RET
;********************
T1017:
LDBR R0,0X10,1
LDBR R1,0X27,1
MOVXR R20,1,1
IJNE R20,0,E1017
IJNE R21,0,N1017
RET
N1017:
IJNE R21,1,C1017
CALL O1017
RET
E1017:
NOP
RET
C1017:
IJNE R21,2,E1017
LDBR R101,0x06,1 ;命令码
LDBR R102,0x00,1 ;
LDBR R103,0x0A,1
LDBR R104,0x00,1
LDBR R105,0x00,1
CALL U4TX
LDBR R20,0,1
LDBR R21,0,1
MOVXR R20,0,1 ;写0x0000进变量
RET
O1017:
LDBR R101,0x06,1 ;命令码
LDBR R102,0x00,1 ;
LDBR R103,0x0A,1
LDBR R104,0x00,1
LDBR R105,0x01,1
CALL U4TX
LDBR R20,0,1
LDBR R21,0,1
MOVXR R20,0,1 ;写0x0000进变量
RET
T1018:
LDBR R0,0X10,1
LDBR R1,0X28,1
MOVXR R20,1,1
IJNE R20,0,E1018
IJNE R21,0,N1018
RET
N1018:
IJNE R21,1,C1018
CALL O1018
RET
E1018:
NOP
RET
C1018: IJNE R21,2,E1018
LDBR R101,0x06,1 ;命令码
LDBR R102,0x00,1 ;
LDBR R103,0x01,1
LDBR R104,0x00,1
LDBR R105,0x00,1
CALL U4TX
LDBR R20,0,1
LDBR R21,0,1
MOVXR R20,0,1 ;写0x0000进变量
RET
O1018:
LDBR R101,0x06,1 ;命令码
LDBR R102,0x00,1 ;
LDBR R103,0x01,1
LDBR R104,0x00,1
LDBR R105,0x01,1
CALL U4TX
LDBR R20,0,1
LDBR R21,0,1
MOVXR R20,0,1 ;写0x0000进变量
RET
U4TX:
LDBR R100,0x01,1 ;
LDBR R10,0x06,1
CRCA R100,R120,R10 ;6字节做ANSI CRC计算
MOV R120,R106,2 ;赋值给R106 R107
LDBR R9,0x08,1
COMTXD 4,R100,R9
RET
</font>