主程序如下:
ORG 0000H
LJMP L001E
ORG 0003H
LJMP L05E6
ORG 0023H
LJMP server
MOV C,P0.7
NOP
JC L001E
LJMP L052C ;
L001E: MOV C, P0.7 ;IC40开关1(ON),3(ON),写系数
NOP
JC L002C ;IC40开关2(ON),4(ON),测流量
L0029: LJMP L037A ;IC40开关2(ON),4(OFF),测频率
L002C: LCALL L003B ;初始化
LCALL L01D2 ;输入频率
LCALL L01B7H ;流量进行累计
LCALL L0085 ;显示
ORL 87H, #02H
L003B: MOV R0, #60H ;60H~6FH清0
MOV B, #10H
LCALL L005B
MOV C, P3.3
JC L005A
MOV R0, #40H ;40H~6FH清0
MOV B, #10H
LCALL L005B
MOV R0, #50H ;50H~6FH清0
MOV B, #10H
LCALL L005B
L005A: RET
L005B: MOV @R0, #00H
INC R0
DJNZ B, L005B
RET
ORG 0037EH
L037E: NOP
JNB P0.7, L0385
LJMP L052C ;写系数
L0385: MOV 38H, #00H ;以下是测频率
MOV 39H, #00H
MOV 3AH, #00H
MOV 3BH, #00H
MOV 3CH, #00H
MOV 3DH, #00H
MOV 3EH, #00H
MOV 3FH, #00H
L03A1: CLR C
MOV 2EH, #00H
MOV 2FH, #00H
ACALL L046E
MOV A, R0
NOP
MOV B, #64H
DIV AB
MOV 32H, A
MOV A, B
MOV B, #0AH
DIV AB
MOV 31H, A
MOV 30H, B
MOV 33H, #00H
MOV 34H, #00H
MOV 35H, #00H
MOV 36H, #00H
MOV 37H, #00H
ACALL L0411
ACALL L03EF
MOV C, P3.3
JC L03EC
MOV 38H, #00H
MOV 39H, #00H
MOV 3AH, #00H
MOV 3BH, #00H
MOV 3CH, #00H
MOV 3DH, #00H
MOV 3EH, #00H
MOV 3FH, #00H
L03EC: ORL 87H, #02H
L03EF: ORL P1, #0FFH
MOV B, #0EH
CLR A
MOV DPTR, #0359H ;显示数据
L03F9: MOVC A, @A+DPTR
MOV R0, A
MOV A, @R0
ORL A, #0F0H
ANL P1, A
CLR A
INC DPTR
MOVC A, @A+DPTR
ANL P1, A
ORL P1, #0F0H
ORL P1, #0FFH
CLR A
INC DPTR
DJNZ B, L03F9
RET
L0411: MOV R0, #30H
MOV R1, #38H
MOV B, #08H
CLR C
L0419: MOV A, @R1
ADDC A, @R0
DA A
MOV C, ACC.4
CLR ACC.4
MOV @R1, A
INC R0
INC R1
DJNZ B, L0419
RET
ORG 0359
DB 4BH,0DFH,4AH,0CFH,49H,9FH,49H,8FH,47H,7FH,46H,6FH,45H,5FH,44H,4FH
DB 43H,3FH,38H,2FH,37H,1FH,36H,0FH,2FH,0AFH,2DH,0BFH
ORG 000BH
LJMP L05E6
ORG 052CH
L052C: MOV SP, #38H
MOV IE, #88H
MOV PSW, #00H
MOV TMOD, #15H
MOV TL0, #00H
MOV TH0, #00H
MOV TL1, #00H
MOV TH1, #00H
SETB TCON.TR0
SETB TCON.TR1
SETB P3.1
MOV P3, #0FFH
L0552: LCALL L0BD3 ;键盘输入
L0579: CJNE A, #0FBH, L0552
LCALL L0814 ;写系数
RET
ORG 05E6H ;定时显示
L05E6: PUSH ACC
PUSH PSW
MOV PSW, #08H
MOV TL1, #00H
MOV TH1, #00H
CLR A
MOV 78H, A
SETB 01H
MOV R0, #25H
MOV R1, #00H
MOV R7, #0CH
L05FE: MOV A, #00H
ORL A, #0F0H
ANL P1, A
ANL P1, A
CLR A
MOV A, #0BFH
ANL P1, A
ORL P1, #0F0H
ORL P1, #0FFH
MOV A, #00H
ORL A, #0F0H
ANL P1, A
ANL P1, A
CLR A
MOV A, #0AFH
ANL P1, A
ORL P1, #0F0H
ORL P1, #0FFH
MOV A, R0
CJNE A, 00H, L0635
JNB 0AH, L0635
CPL 0BH
JNB 0BH, L0635
MOV A, #0FH
LJMP L0636
L0635: MOV A, @R0
L0636: ANL A, #0FH
SWAP A
ORL A, R1
SWAP A
MOV P1, A
ORL A, #0F0H
MOV P1, A
INC R0
INC R1
CJNE R1, #0AH, L0648
INC R1
INC R1
L0648: DJNZ R7, L05FE
POP PSW
POP ACC
RETI
四、接口及外设驱动程序
1、输入部分程序:
L01D2: MOV R0, P2 ;读入P2中的频率信号
CLR P3.7
NOP
NOP
NOP
SETB P3.7
NOP
NOP
NOP
MOV R1, #70H ;读出的数据存入位置
MOV R6, #0A0H ;27C16中的设备地址
MOV R7, #08H
L01E4: LCALL L0223 ;根据相应的频率从27C16中读取每秒流量参数
MOV @R1, A
INC R1
MOV A, R6
ADD A, #02H ;
MOV R6, A
DJNZ R7, L01E4 ;读8位参数
PUSH 00H
MOV R1, #70H
MOV R0, #28H
MOV R3, #08H
L01F7: MOV A, @R1
MOV @R0, A
DEC R0
INC R1
DJNZ R3, L01F7 ;将70H中的数据送入20H~27H中
MOV R0, #20H ;将20H~27H中的数据送到60H~67H中。
MOV R1, #67H
MOV R3, #08H
L0203: MOV A, @R0
MOV @R1, A
INC R0
INC R1
DJNZ R3, L0203
MOV 60H, #36H ;将60H中的每秒流量换算成米3/小时
MOV R0, #20H
MOV R1, #60H
MOV R3, #07H
LCALL L02FC
MOV R0, #20H ;将瞬时流量换算成十进制BCD送入到30H~3FH中
MOV R1, #3FH
MOV R2, #08H
LCALL L034A
POP 00H
RET
计算累计流量送入50H中,程序如下
L01B7: mov R0, #67H ;将60H~67H中的瞬时流量二进制值累加到50H~57H
MOV R1, #57H
MOV B, #08H
CLR C
L01BF: MOV A, @R1
ADDC A, @R0
DA A
MOV @R1, A
DEC R0
DEC R1
DJNZ B, L01BF
MOV R0, #50H ;将50H~57H中的二进制换算成十进制BCD码
MOV R1, #4FH ;送到40H~47H中
MOV R2, #08H
LCALL L034A
RET
2、显示部分:
程序如下:
L0085: ORL P1, #0FFH ;P1口置1,4FH~40H中是要显示的数据(高~低)
MOV A, 4FH ;最高位是否为0
NOP
NOP
MOV A, 4FH
ANL A, #0ffH
JZ L009E ;为0转移
MOV DPTR, #0F10H ;第一段显示数据(此时数据为最大)
MOV 2FH, #0a0h ;送小数点数据到2FH中
LJMP L00DD
L009E: MOV A, 4EH ;次高位是否为0
NOP
NOP
MOV A, 4EH
ANL A, #0FFH
JZ L00B1 ;为0转移
MOV DPTR, #0F20H ;第二段显示数据
MOV 2FH, #21H ;送小数点数据到2FH中
LJMP L00DD
L00B1: MOV A, 4DH
NOP
NOP
MOV A, 4DH
ANL A, #0FFH
JZ L00C4 ;为0转移
MOV DPTR, #0F30H ;第三段显示数据
MOV 2FH, #22H ;送小数点数据到2FH中
LJMP L00DD
L00C4: MOV A, 4CH
NOP
NOP
MOV A, 4CH
ANL A, #0FFH
JZ L00D7 ;为0转移
MOV DPTR, #0F40H ;第四段显示数据
MOV 2FH, #24H ;送小数点数据到2FH中
LJMP L00DD
L00D7: MOV DPTR, #0F50H ;第五段显示数据
MOV 2FH, #28H ;送小数点数据到2FH中
L00DD: MOV B, #0DH ;显示数据中的数据个数
MOV A, 2FH
ANL A, #0FH
MOV 2DH, A
MOV A, 2FH
ANL A, #0F0H
SWAP A
MOV 2FH, A
CLR A
L00EE: MOVC A, @A+DPTR ;取相应段的数据进行显示
MOV R0, A
MOV A, @R0
ORL A, #0F0H
ANL P1, A
NOP
NOP
NOP
NOP
NOP
ANL p1,a
CLR A
INC DPTR
MOVC A, @A+DPTR
ANL P1, A
NOP
NOP
NOP
NOP
ANL P1, A
ORL P1, #0F0H
ORL P1, #0FFH
CLR A
INC DPTR
DJNZ B, L00EE
END
ORG 0F10H ;以下为显示数据,浮动五位。
DB 4FH,0DFH,4EH,0CFH,4DH,9FH,4CH,8FH,4BH,7FH,4AH,6FH,49H,5FH,48H,4FH
DB 47H,3FH,38H,2FH,37H,1FH,36H,0FH,2FH,0AFH,2DH,0BFH
ORG 0F20 H
DB 4EH,0DFH,4DH,0CFH,4CH,9FH,4BH,8FH,4AH,7FH,49H,6FH,48H,5FH,47H,4FH
DB 46H,3FH,38H,2FH,37H,1FH,36H,0FH,2FH,0AFH,2DH,0BFH
ORG 0F30 H
DB 4DH,0DFH,4CH,0CFH,4BH,9FH,4AH,8FH,49H,7FH,48H,6FH,47H,5FH,46H,4FH
DB 45H,3FH,38H,2FH,37H,1FH,36H,0FH,2FH,0AFH,2DH,0BFH
ORG 0F40 H
DB 4CH,0DFH,4BH,0CFH,4AH,9FH,49H,8FH,48H,7FH,47H,6FH,46H,5FH,45H,4FH
DB 44H,3FH,38H,2FH,37H,1FH,36H,0FH,2FH,0AFH,2DH,0BFH
ORG 0F50 H
DB 4BH,0DFH,4AH,0CFH,49H,9FH,49H,8FH,47H,7FH,46H,6FH,45H,5FH,44H,4FH
DB 43H,3FH,38H,2FH,37H,1FH,36H,0FH,2FH,0AFH,2DH,0BFH
3、键盘部分:
L0BD3: SETB P3.2
SETB P3.3
SETB p3.4
SETB P3.5
MOV A, P3
ORL A, #0D7H
CJNE A, #0FFH, L0BF0
MOV R6, #10H
ACALL L0BFE
MOV A, P3
ORL A, #0D7H
CJNE A, #0FFH, L0BD3
CLR A
CLR 07H
SJMP L0BFD
L0BF0: MOV R6, #10H
ACALL L0BFE
MOV A, P3
ORL A, #0D7H
CJNE A, #0FFH, L0BFD
SJMP L0BD3
L0BFD: RET
L0BFE: NOP
LCALL L07D3 ;延时程序
DJNZ R6, L0BFE
RET
4、通讯程序:
采用中断方式传送数据给计算机。
ORG 0023H
server: push acc
push 00h
push 01h
push 02h ;保护断点
JBC TI,server1 ;中断程序将累计流量传给算机
RETI
Server1: mov R1,#50h
Mov R0,#08h
mov a,@r1
MOV SBUF, A ;传送一个位
Djnz R0,server1
JB P,ERROR ;偶校验
ANL A,#7FH ;去掉校验位
Server2: mov R1,#60h ; 中断程序将瞬时流量传给算机
Mov R0,#08h
mov a,@r1
MOV SBUF, A ;传送一个位
Djnz R0,server1
JB P,ERROR ;偶校验
ANL A,#7FH ;去掉校验位
ERROR: pop acc ;恢复断点
pop 02h
pop 01h
pop 00h
RETI
四、结束语
流量计的抗干扰能力强,在流量全范围内可非线性调整、内部无可调件、使用维护简单等优点,可以用来测量、变送及现场显示封闭工业管道中液体、气体和蒸汽的流量及总量。从投用到现在,应用的效果非常好,是一种理想的仪表 |