⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hexbcd.asm

📁 Library for the 8051 microcontroller. such as math routine, hexBCD, LCD, Keyboard, I2C, Remote, Ke
💻 ASM
字号:
$MOD51
; 2 BYTE HEX TO 5 DIGITS BCD
;----------------------------------------------------------------------------------------
; Author:  Slobodan Mandaric, Serbia & Montenegro
; June 3rd, 2005.
; Modify: Jan 14th, 2008
; Author:  Herlambang Aribowo, Indonesia

;----------------------------------------------------------------------------------------
; 149 cycles for 2 bytes,  77 cycles for 1 byte
; Result:  <R3...R7>
; All 8 registers are used, and also A and B

;----------------------------------------------------------------------------------------
;Iki routine kanggo inputan 16 byte sing arep di konversi
;Input di <R1&R2>
	MOV	r1,#0AFH	; 175d           
	MOV	r2,#91H		; 91AFH = 37295d 
;----------------------------------------------------------------------------------------
; R7=3, R6=7, ..., R3=5
;----------------------	
	MOV	R5,#0
	MOV	R6,#0
	MOV	R7,#0

	MOV	A,R1
	MOV	B,#10
	DIV	AB
	
	MOV	R3,B		; Lower byte, in R1, is transformed into 2 decade digits,
	MOV	R4,A		; it's OK that the higher one can be greater than 9

	MOV	A,R2		; Higher byte is in R2
	JZ	SPRING		; Spring over if 0
	MOV	B,#10
	DIV	AB

	MOV	R5,B		; Same as for lower byte
	MOV	R6,A

; Value in R5 is 256 times higher than value standing in R3, R4. Mply R5 with 6,
; add to R3, mply R5 with 5, add to R4, mply R5 with 2 and replace itself in R5

	MOV	R0,#05		; Point to R5
	ACALL	TRANSF		; Transform R5 to 3 lower positions

	INC	R0		; Repeat from R6, now all registers are 1 higher
	ACALL	TRANSF		; Transform R6 to 3 higher positions

SPRING:	MOV	R0,#03		; Point to lowest digit

; Adjust to decimal, everything higher than 9 should be, as 1 tenth, added to higher.
; Starting from the lowest digit, divide with 10, keep the rest, and add the 1/10th to
; first higher place (eg. 145, leave 5 and add 14 to the next higher)

	ACALL	DECADJ

	SJMP	$

TRANSF:	MOV	A,@R0
	MOV	B,#6
	MUL	AB
	DEC	R0
	DEC	R0
	ADD	A,@R0
	MOV	@R0,A

	INC	R0
	INC	R0
	MOV	A,@R0
	MOV	B,#5
	MUL	AB
	DEC	R0
	ADD	A,@R0
	MOV	@R0,A

	INC	R0
	MOV	A,@R0
	RL	A		; Mply with 2
	MOV	@R0,A

	RET

DECADJ:	MOV	A,@R0
DECLOP:	MOV	B,#10
	DIV	AB
	MOV	@R0,B
	INC	R0
	ADD	A,@R0
	MOV	@R0,A
	
	CJNE	R0,#7,DECLOP
	RET

END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -