;TLC1549数字电压表程序数字电压表:量程为 5V,精度为0.1V (不带字库12864显示)
CS1 BIT P2.3
CS2 BIT P2.4
D_I BIT P3.6 ;4
R_W BIT P2.5 ;5
E BIT P2.6 ;6
DB0_DB7 EQU P0
X EQU 22H ;页地址
Y EQU 23H ;列地址
COM EQU 24H
DAT EQU 24H
COUNT EQU 25H ;代码倒计数单元
CODE0 EQU 26H ;表格起始地址,赋0值后与DPTR合成查表指针地址
MUL_ EQU 26H ;显示数字时,暂存单元(要显示的数是几就在里面存几)
CLK1 BIT P3.4
DATA1 BIT P3.5
CS BIT P3.7
ORG 0000H
JMP MAIN
ORG 0030H
MAIN: MOV SP,#60H
ACALL INT
SETB CS1
SETB CS2
ACALL CLEAR
ACALL SY
BEGIN: ACALL TLC1549
MOV R3,58H ;;********
MOV R2,59H
MOV R7,#0AH
MOV R6,#00H
ACALL MULD
MOV R7,#0CCH
ACALL D457
MOV A,R3
ACALL HBCD
MOV R3,A
CALL TUBCD
CALL DSP1
ACALL DEL
JMP BEGIN
TUBCD: MOV A,R3
ANL A,#0FH
MOV 30H,A ;低位
MOV A,R3
SWAP A
ANL A,#0FH
MOV 31H,A
RET
HBCD: MOV B,#100 ;分离出百位,存放在R3中
DIV AB
MOV R3,A
MOV A,#10 ;余数继续分离十位和个位
XCH A,B
DIV AB
SWAP A
ORL A,B ;将十位和个位拼装成BCD码
RET
HB2: CLR A ; 双字节十六进制转BCD码
MOV R3,A
MOV R4,A
MOV R5,A
MOV R2,#10H ; 转换双字节十六进制整数
HB3: MOV A,R7 ; 从高端移出待转换数的一位到CY中
RLC A
MOV R7,A
MOV A,R6
RLC A
MOV R6,A
MOV A,R5 ;BCD码带进位自身相加,相当于乘2
ADDC A,R5;
DA A ; 十进制调整
MOV R5,A
MOV A,R4
ADDC A,R4
DA A
MOV R4,A
MOV A,R3
ADDC A,R3
MOV R3,A ; 双字节十六进制数的万位数不超过6,不用调整
DJNZ R2,HB3 ; 处理完16bit
RET
MULD: MOV A,R3 ;计算R3乘R7
MOV B,R7
MUL AB
MOV R4,B ;暂存部分积
MOV R5,A
MOV A,R3 ;计算R3乘R6
MOV B,R6
MUL AB
ADD A,R4 ;累加部分积
MOV R4,A
CLR A
ADDC A,B
MOV R3,A
MOV A,R2 ;计算R2乘R7
MOV B,R7
MUL AB
ADD A,R4 ;累加部分积
MOV R4,A
MOV A,R3
ADDC A,B
MOV R3,A
CLR A
RLC A
XCH A,R2 ;计算R2乘R6
MOV B,R6
MUL AB
ADD A,R3 ;累加部分积
MOV R3,A
MOV A,R2
ADDC A,B
MOV R2,A
RET
D457: CLR C
MOV A,R4
SUBB A,R7
JC DV50
SETB OV ;商溢出
RET
DV50: MOV R6,#8 ;求平均值(R4R5/R7-→R3)
DV51: MOV A,R5
RLC A
MOV R5,A
MOV A,R4
RLC A
MOV R4,A
MOV F0,C
CLR C
SUBB A,R7
ANL C,/F0
JC DV52
MOV R4,A
DV52: CPL C
MOV A,R3
RLC A
MOV R3,A
DJNZ R6,DV51
MOV A,R4 ;四舍五入
ADD A,R4
JC DV53
SUBB A,R7
JC DV54
DV53: INC R3
DV54: CLR OV
RET
TLC1549: SETB CLK1 ;读AD数据
SETB CS
SETB DATA1
CLR CS
CLR CLK1
MOV C,DATA1
MOV 22H.1,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV 22H.0,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.7,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.6,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.5,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.4,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.3,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.2,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.1,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
MOV C,DATA1
MOV ACC.0,C
SETB CLK1
NOP
NOP
CLR CLK1
NOP
NOP
SETB CS
CLR CLK1
CLR CLK1
MOV 58H,A ;低位送入58H
CLR A
MOV C,22H.0
MOV ACC.0,C
MOV C,22H.1
MOV ACC.1,C
ANL A,#03H
MOV 59H,A ;高位送入59H
RET
DSP1: SETB CS2
CLR CS1
MOV X,#0BAH
MOV Y,#50H
MOV DPTR,#DDB
MOV MUL_,31H
ACALL DISP_
MOV X,#0BAH
MOV Y,#60H
MOV MUL_,30H
ACALL DISP_
MOV X,#0BAH
MOV Y,#58H
MOV DPTR,#TAB1
MOV MUL_,#00H
ACALL DISP_
RET
;************************8位字宽显示子程序: (CODE0待设)**********************
DISP_: MOV B,#10H ;要显示的数是几就用几乘以16,得到基址起始地址
MOV A,MUL_
MUL AB
MOV CODE0,A
MOV 39H,#02H
MOV COUNT,#08H
LP_: MOV COM,X ;设置页地址
LCALL INST
MOV COM,Y ;设置列地址
LCALL INST
W_: MOV A,CODE0
MOV C A,@A+DPTR
MOV DAT,A
LCALL DATA_
INC CODE0
DJNZ COUNT,W_
DJNZ 39H,LP1_
RET
LP1_: INC X
MOV COUNT,#08H
AJMP LP_
;***************************16位字宽显示子程序**********************
DISP: MOV 39H,#02H
MOV CODE0,#00H
MOV COUNT,#10H ;根据字宽及象素的不同而改变 DISP中的COUNT根据字高及象素改变CODE0
LP: MOV COM,X ;设置页地址
LCALL INST
MOV COM,Y ;设置列地址
LCALL INST
W: MOV A,CODE0
MOV C A,@A+DPTR
MOV DAT,A
LCALL DATA_
INC CODE0
DJNZ COUNT,W
DJNZ 39H,LP1
RET
LP1: INC X
MOV COUNT,#10H
AJMP LP
;***********************以下为字符显示子程序块*************************
SY: SETB CS1 ;开机
CLR CS2
MOV X,#0BAH
MOV Y,#40H
MOV DPTR,#TAB2 ;
CALL DISP
MOV X,#0BAH
MOV Y,#50H
MOV DPTR,#TAB3 ;
CALL DISP
MOV X,#0BAH
MOV Y,#60H
MOV DPTR,#TAB4 ;
CALL DISP
MOV X,#0BAH
MOV Y,#70H
MOV DPTR,#TAB5 ;
CALL DISP
CLR CS1
SETB CS2
MOV X,#0BAH
MOV Y,#40H
MOV DPTR,#TAB6 ;
CALL DISP
MOV X,#0BAH
MOV Y,#70H
MOV DPTR,#TAB7 ;
CALL DISP
RET
INST: LCALL BUSY ;写指令
SETB E
CLR D_I
CLR R_W
MOV DB0_DB7,COM
CLR E
RET
DATA_: LCALL BUSY ;写数据
SETB E
SETB D_I
CLR R_W
MOV DB0_DB7,DAT
CLR E
RET
BUSY: CLR D_I ;测忙
SETB R_W
BUSY1: MOV DB0_DB7,#0FFH
SETB E
MOV A,DB0_DB7
CLR E
JB ACC.7,BUSY1
RET
CLEAR: MOV R4,#00H ;清屏
CLEAR1: MOV A,R4
ORL A,#0B8H
MOV COM,A
ACALL INST
MOV COM,#40H
ACALL INST
MOV R3,#40H
CLEAR2: MOV DAT,#00H
LCALL DATA_
DJNZ R3,CLEAR2
INC R4
CJNE R4,#08H,CLEAR1
RET
INT: MOV COM,#0C0H ;初始化
ACALL INST
MOV COM,#3FH
ACALL INST
RET
;***********************************************
DEL: MOV R7,#01H
DEL1: MOV R6,#0FFH
DEL2: MOV R5,#0FFH
DJNZ R5,$
DJNZ R6,DEL2
DJNZ R7,DEL1
RET
DDB:
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
DB 000H,010H,010H,0F8H,000H,000H,000H,000H,000H,020H,020H,03FH,020H,020H,000H,000H ; "1" 1
DB 000H,070H,008H,008H,008H,088H,070H,000H,000H,030H,028H,024H,022H,021H,030H,000H ; "2" 2
DB 000H,030H,008H,088H,088H,048H,030H,000H,000H,018H,020H,020H,020H,011H,00EH,000H ; "3" 3
DB 000H,000H,0C0H,020H,010H,0F8H,000H,000H,000H,007H,004H,024H,024H,03FH,024H,000H ; "4" 4
DB 000H,0F8H,008H,088H,088H,008H,008H,000H,000H,019H,021H,020H,020H,011H,00EH,000H ; "5" 5
DB 000H,0E0H,010H,088H,088H,018H,000H,000H,000H,00FH,011H,020H,020H,011H,00EH,000H ; "6" 6
DB 000H,038H,008H,008H,0C8H,038H,008H,000H,000H,000H,000H,03FH,000H,000H,000H,000H ; "7" 7
DB 000H,070H,088H,008H,008H,088H,070H,000H,000H,01CH,022H,021H,021H,022H,01CH,000H ; "8" 8
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,000H,031H,022H,022H,011H,00FH,000H ; "9" 9
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
DB 000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H ; "0" 0
TAB1:
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,030H,030H,000H,000H,000H,000H,000H ; "." 0
TAB2:
DB 000H,000H,040H,042H,05CH,048H,040H,040H,07FH,040H,050H,04EH,044H,0C0H,000H,000H ;
DB 000H,000H,020H,022H,022H,022H,022H,022H,022H,022H,022H,022H,022H,07FH,000H,000H ; "当" 0
TAB3:
DB 008H,008H,0E8H,0A8H,0A9H,0AEH,0EAH,008H,008H,0C8H,00CH,00BH,0EAH,008H,008H,000H ;
DB 000H,000H,07FH,004H,024H,044H,03FH,000H,000H,01FH,040H,080H,07FH,000H,000H,000H ; "前" 1
TAB4:
DB 000H,000H,0F8H,048H,048H,048H,048H,0FFH,048H,048H,048H,048H,0F8H,000H,000H,000H ;
DB 000H,000H,00FH,004H,004H,004H,004H,03FH,044H,044H,044H,044H,04FH,040H,070H,000H ; "电" 2
TAB5:
DB 000H,000H,0FEH,002H,042H,042H,042H,042H,0FAH,042H,042H,042H,062H,042H,002H,000H ;
DB 020H,018H,027H,020H,020H,020H,020H,020H,03FH,020H,021H,02EH,024H,020H,020H,000H ; "压" 3
TAB6:
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H ;
DB 000H,000H,036H,036H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H ; ":" 0
TAB7:
DB 008H,078H,088H,000H,000H,0C8H,038H,008H,00H,00H,00H,00H,00H,00H,00H,00H; "V" 1
DB 000H,000H,007H,038H,00EH,001H,000H,000H,00H,00H,00H,00H,00H,00H,00H,00H
END