DL2: DJNZ R7,DL2 DJNZ R6,DL1 RET DELAY10: MOV R6,#20 ;10MS延时 D3: MOV DJNZ RET DJNZ R6,D3 R5,#255 R5,$ DELAY125: MOV R6,#255 ;125MS延时 D1: MOVR5,#255 DJNZ DJNZ RET MOV R7,#8 ;1S延时 R7,D2 R5,$ R6,D1 DELAY1S: DJNZ RET D2: LCALLDELAY125 ;PID算法子程序; PID: MOV R5,31H MOV R4,32H MOV R3,2AH MOV R2,#00H ACALL CPL1 ACALL DSUM MOV 39H,R7 MOV 3AH,R6 MOV R5,35H MOV R4,36H MOV R0,#4AH ACALL MULT1 MOV R5,39H MOV R4,3AH MOV R3,3BH MOV R2,3CH ACALL CPL1 ACALL DSUM MOV R5,33H MOV R4,34H MOV R0,#46H ACALL MULT1 MOV R5,49H MOV R4,48H MOV R3,4DH MOV R2,4CH ACALL DSUM MOV 4AH,R7 MOV 4BH,R6 MOV R3,4AH MOV R2,4BH MOV R5,2FH MOV R4,30H ACALL DSUM MOV 2FH,R7 MOV 30H,R6 MOV 3DH,3BH MOV 3EH,3CH MOV 3BH,39H MOV 3CH,3AH RET ;双字节加法程序; ; R5R4+R3R2=R7R6 ; DSUM: MOV A,R4 ADD A,R2 MOV R6,A MOV A,R5 ADDC A,R3 MOV R7,A RET ;双子节求补程序对R3R2求补; CPL1: MOV A,R2 CPL A ADD A,#01H MOV R2,A MOV A,R3 CPL A ADDC A,#00H MOV R3,A RET ;双字节带符号乘法子程序 ; MULT1: MOV A,R7 RLC A MOV 21H.0,C JNC POS1 MOV A,R6 CPL A ADD A,#01H MOV R6,A MOV A,R7 CPL A ADDC A,#00H MOV R7,A POS1: MOV A,R5 RLC A MOV 22H.0,C JNC POS2 MOV A,R4 CPL A ADD A,#01H MOV R4,A MOV A,R5 CPL A ADDC A,#00H MOV R5,A POS2: ACALL MULT MOV C,21H.0 ANL C,22H.0 JC TPL2 MOV C,21H.0 ORL C,22H.0 JNC TPL2 DEC R0 MOV A,@R0 CPL A ADD A,#01H MOV @R0,A INC R0 MOV A,@R0 CPL A ADDC A,#00H MOV @R0,A TPL2: RET ;双字节二进制无符号数乘法子程序; MULT: MOV A,R6 MOV B,R4 MUL AB MOV @R0,A INC R0 MOV A,B MOV @R0,A MOV A,R6 MOV B,R5 MUL AB ADD A,@R0 MOV @R0,A CLR A ADDC A,B INC R0 MOV @R0,A MOV A,R7 MOV B,R4 MUL AB DEC R0