KG EQU P3.1 ;档位选择控制
K EQU P3.2 ;门控开关控制
RES EQU P3.3;4040复位
E EQU P3.5 ;LCD RS
RW EQU P3.6;LCD RW
RS EQU P3.7;LCD E
ORG 0000H
MOV SP,#60H 堆键
SETB RES ;4040清零
;显示屏初始化
SETB E
MOV P1,#00000001B ;清屏
ACALL ENABLE 吊用ENABLE子程序
MOV P1,#00001100B ;显示器开、光标开、闪烁开
ACALL ENABLE
MOV R0,#0EFH 付值到R0寄存器
TT: NOP
DJNZ R0,TT ;延时
MOV TMOD,#00000101B
;清计数器及计数RAM
START: MOV P0,#0FFH
MOV P2,#0FFH
MOV TL0,#00H
MOV TH0,#00H
JB KG,GHZ ;读档位控制开关,为1转为另一档
CLR RES ;使4040可计数
SETB TR0 ;启动计数器0
SETB K ;开计数开关并延时1S,MCU时钟频率为12.8M
MOV R1,#08H
TIME01:
MOV R2,#0ffH
TIME02:
MOV R3,#0FFH
TIME03: 延时子程序
DJNZ R3,TIME03
DJNZ R2,TIME02
DJNZ R1,TIME01
MOV R1,#01H
TIME11: 延时子程序
MOV R2,#027H
TIME12:
MOV R3,#0FFH
TIME13:
DJNZ R3,TIME13
DJNZ R2,TIME12
DJNZ R1,TIME11
MOV R1,#01H
TIME21:
MOV R2,#01H
TIME22:
MOV R3,#33H
TIME23:
DJNZ R3,TIME23
DJNZ R2,TIME22
DJNZ R1,TIME21
;NOP ;时间精确调整
CLR K ;关计数开关
NOP
NOP
NOP
CLR TR0 ;关计数器0
;读入计数值
MOV 20H,P0 将端口值记入到地址20H
MOV 21H,P2
MOV 22H,TL0
MOV 23H,TH0
MOV A,22H
SWAP A
MOV 22H,A
ANL 21H,#0FH
ANL A,#0F0H
ORL 21H,A
MOV A,23H
SWAP A
MOV 23H,A
ANL 22H,#0FH
ANL A,#0F0H
ORL 22H,A
ANL 23H,#0FH
SETB RES
AJMP COUNT
GHZ:
CLR RES ;使4040可计数
SETB TR0 ;启动计数器0
SETB K ;开计数开关并延时4S,MCU时钟频率为12.8M
MOV R1,#020H
TIME01G:
MOV R2,#0ffH
TIME02G:
MOV R3,#0FFH
TIME03G:
DJNZ R3,TIME03G
DJNZ R2,TIME02G
DJNZ R1,TIME01G
MOV R1,#01H
TIME11G:
MOV R2,#09cH
TIME12G:
MOV R3,#0FFH
TIME13G:
DJNZ R3,TIME13G
DJNZ R2,TIME12G
DJNZ R1,TIME11G
MOV R1,#01H
TIME21G:
MOV R2,#01H
TIME22G:
MOV R3,#0DFH
TIME23G:
DJNZ R3,TIME23G
DJNZ R2,TIME22G
DJNZ R1,TIME21G
NOP ;时间精确调整
CLR K ;关计数开关
NOP
NOP
NOP
CLR TR0 ;关计数器0
;读入计数值
MOV 20H,P0
MOV 21H,P2
MOV 22H,TL0
MOV 23H,TH0
;将计数值乘16
MOV A,21H
SWAP A
MOV 21H,A
ANL A,#0F0H
MOV A,20H
SWAP A
MOV 20H,A
ANL 20H,#0F0H
ANL A,#0FH
ORL 21H,A
SETB RES
;多(四)字节二转十,入口R0为二进制低位字节地址指针,R7为字节数,出口R1为BCD码结果低位字节地址指针
COUNT: MOV R0,#20H
MOV R1,#30H
MOV R7,#04H
BMBCD: MOV A,R0
MOV R5,A
MOV A,R1
MOV R6,A
MOV A,R7
MOV R3,A
INC R3
CLR A
CLBCD: MOV @R1,A
INC R1
DJNZ R3,CLBCD
MOV A,R7
MOV B,#08H
MUL AB
MOV R3,A
LP0: MOV A,R5
MOV R0,A
MOV A,R7
MOV R2,A
CLR C
LP1: MOV A,@R0
RLC A
MOV @R0,A
INC R0
DJNZ R2,LP1
MOV A,R6
MOV R1,A
MOV A,R7
MOV R2,A
INC R2
LP2: MOV A,@R1
ADDC A,@R1
DA A
MOV @R1,A
INC R1
DJNZ R2,LP2
DJNZ R3,LP0
MOV R0,#30H
MOV R1,#24H
ABC:MOV A,@R0
ANL A,#00001111B
ORL A,#30H
MOV @R1,A
MOV A,@R0
ANL A,#11110000B
RL A
RL A
RL A
RL A
ORL A,#30H
INC R1
MOV @R1,A
INC R0
INC R1
CJNE R0,#036H,ABC
;从高往底判断,不是0就开始显示
MOV 02EH,#20H
MOV R1,#02DH
CJNE @R1,#030H,MHZ;2D
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,MHZ;2C
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,MHZ;2B
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,MHZ;2A
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,KHZ;29
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,KHZ;28
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,KHZ;27
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,HZ;26
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,HZ;25
MOV @R1,#020H
DEC R1
CJNE @R1,#030H,HZ;24
AJMP NO_OK
MHZ:
MOV R0,#23H
MOV @R0,#4DH;23
DEC R0
MOV @R0,#48H;22
DEC R0
MOV @R0,#7AH;21
DEC R0
MOV @R0,#20H;20
MOV A,02CH
MOV 02DH,A
MOV A,02BH
MOV 02CH,A
MOV A,02AH
MOV 02BH,A
MOV 02AH,#2EH
AJMP HZ00
KHZ:
MOV R0,#23H
MOV @R0,#4BH;23
DEC R0
MOV @R0,#48H;22
DEC R0
MOV @R0,#7AH;21
DEC R0
MOV @R0,#20H;20
MOV A,029H
MOV 02AH,A
MOV A,028H
MOV 029H,A
MOV A,027H
MOV 028H,A
MOV 027H,#2EH
AJMP HZ00
HZ:
MOV R0,#23H
MOV @R0,#48H;23
DEC R0
MOV @R0,#7AH;22
DEC R0
MOV @R0,#20H;21
DEC R0
MOV @R0,#20H;20
HZ00:MOV 10H,#053H;
MOV 011H,#49H;
MOV 012H,#47H
MOV 013H,#4EH
MOV 014H,#41H
MOV 015H,#4CH
MOV 016H,#20H
MOV 017H,#46H
MOV 018H,#52H
MOV 019H,#45H
MOV 01AH,#51H
MOV 01BH,#55H
MOV 01CH,#45H
MOV 01DH,#4EH
MOV 01EH,#43H
MOV 01FH,#59H
AJMP OK
NO_OK:;没有信号时显示的数据
MOV 010H,#4EH
MOV 011H,#4FH
MOV 012H,#20H
MOV 013H,#49H
MOV 014H,#4EH
MOV 015H,#50H
MOV 016H,#55H
MOV 017H,#54H
MOV 018H,#20H
MOV 019H,#53H
MOV 01AH,#49H
MOV 01BH,#47H
MOV 01CH,#4EH
MOV 01DH,#41H
MOV 01EH,#4CH
MOV 01FH,#21H
MOV R0,#20H
BBB: MOV @R0,#020H
INC R0
CJNE R0,#030H,BBB
OK:
ACALL DISPLAY
AJMP START
DISPLAY:
MOV R0,#010H
;显示第一行
MOV P1,#00111000B ;8位2行5x7点阵
ACALL ENABLE
MOV P1,#00000110B ;文字不动,光标自动右移
ACALL ENABLE
MOV P1,#10000000B ;写入显示起始地址(第一行第一个位置)
ACALL ENABLE
DISPLAY1 :MOV P1,@R0 ;第一行第N个位置
ACALL WRITE
INC R0
CJNE R0,#020H,DISPLAY1
;显示第二行
MOV P1,#00000100B ;文字不动,光标自动左移
ACALL ENABLE
MOV P1,#00111100B ;8位2行5x10点阵
ACALL ENABLE
MOV P1,#0CEH ;写入显示起始地址(第二行第十五个位置)
ACALL ENABLE
DISPLAY2: MOV P1,@R0 ;第二行第15个位置
ACALL WRITE
INC R0
CJNE R0,#02EH,DISPLAY2
RET
ENABLE: CLR RS ;写入控制命令的子程序
CLR RW
CLR E
ACALL DELAY
SETB E
RET
WRITE: CLR RS ;显示一个字符的子程序
SETB RS ;RS=1
CLR RW ;RW=0
CLR E ;E=0
ACALL DELAY
SETB E ;E=1
RET
DELAY: MOV P1,#0FFH ;判断液晶显示器是否忙的子程序
CLR RS
SETB RW
CLR E
NOP
SETB E
JB P1.7,DELAY ;如果P1.7为高电平表示忙就循环等待
RET
END
我知道这个有一定难度,也不是每个人都能翻译的出来的,希望高手帮下忙,急求把它翻译成C程序