16位二进制转换为bcd码的c51汇编程序(16 bit binary converted to BCD code C51 assembler)
16位二进制转换为bcd码的c51汇编程序(16 bit binary converted to BCD code C51 assembler)
Algorithm 16 bit binary code to BCD and 51 assembly:
N=b15~b0
N=[b15~b8]*256+[b7~b0]
=[b15~b12]*4096+[b11~b0]
Four, the high [b15~b12] value range is 0~15, represents the number 4096
N=[b15~b12]*4000+{[b15~b12]* (100-4) +[b11~b0]}
X [b15~b12], a:
N=x*4000+{x* (100-4) +[b11~b0]
Namely: n=4*x (1000) +x (100) +[b11~b0]-4*x
Back on the site: [b11~b0]-4*x, if less than 356, is directly converted into BCD code, if
Larger, take 11~7 as the number 128 y, plus y at 100, ten plus 3*y, and in
[b6~b0] minus 2*y
There:
N=n=4*x (1000) + (x+y) (100) +3*y (ten) +[b6~b0]-2*y
Thus, it can be defined by the high 9 bits each numerical [b15~b7] transform out decimal places, may be greater than 9, to the end to tidy up.
The rest of the low 7 bits into BCD code is very simple.
This is someone else's ideas, easy to understand, but the assembly is not too good to expect someone to write, write, here is an algorithm of my classmates:
Eight minus one, eighth and 256, (stored in compressed BCD code three bytes 100 2, ten and 5 members, plus 6)
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP INT0
ORG 0100H
MAIN: MOV SP, #60H
MOV R4, #30
MOV TMOD, #01H
MOV TH0, #00H
MOV TL0, #00H
MOV IE, #81H
SETB TR0
SETB IT0
LOOP: LCALL BCD
LCALL UBCD
LOOP1: LCALL XIANSHI
LCALL DELAY
DJNZ R4, LOOP1
AJMP LOOP
BCD: MOV A, #00H
MOV 38H, 41H
MOV 37H, 40H
MOV 34H, A
MOV 35H, A
MOV 36H, A
MOV A, 37H
MOV B, #100
DIV AB
MOV 35H, A
MOV A, B
MOV B, #10
DIV AB
SWAP A
ADD A, B
MOV 36H, A
MOV R3,38H
CJNE R3, #0, JIA
AJMP RETURN
JIA: CLR C
MOV A, 36H
ADDC A, #56H
DA A
MOV 36H, A
MOV A, 35H
ADDC A, #02H
DA A
MOV 35H, A
MOV A, 34H
ADDC A, #0
MOV 34H, A
DJNZ R3, JIA
RETURN:RET
UBCD: MOV A, 34H
CJNE A, #00H, WUWEI
MOV R1, #35H
MOV R0, #36H
MOV A, #00H
XCHD A, @R0
MOV 30H, A
MOV A, @R0
SWAP A
MOV 31H, A
MOV A, #00H
XCHD A, @R1
MOV 32H, A
MOV A, @R1
SWAP A
ADD A, #10
MOV 33H, A
RET
WUWEI: MOV R1, #34H
MOV R0, #35H
MOV A, #00H
XCHD A, @R0
MOV 31H,
一
MOV A,R0
交换
添加,# 10
MO