condec.inc

来自「代码保护功能处于持续发展中。Microchip 承诺将不断改进产品的代码保护功能」· INC 代码 · 共 47 行

INC
47 行
字号
;
;-----------------------------------------------------------
; CONDEC.INC	MPB		1-7-05
; Converts 8-bit binary to decimal
; Returns digits in Huns, Tens, Ones registers
;-----------------------------------------------------------

ADbin	EQU	77	; Binary input value
Huns	EQU	78	; Hundreds digit in decimal value
Tens	EQU	79	; Tens digit in decimal value
Ones	EQU	7A	; Ones digit in decimal value

;-----------------------------------------------------------
; Convert input to decimal 

condec	MOVWF	ADbin		; get ADC result
	CLRF	Huns		; zero hundreds digit
	CLRF	Tens		; zero Tens digit
	CLRF	Ones		; zero Ones digit

; Calclulate hundreds.......................................

	BSF	STATUS,C	; set carry for subtract
	MOVLW	D'100'		; load 100
sub1	SUBWF	ADbin		; and subtract from result
	INCF	Huns		; count number of loops
	BTFSC	STATUS,C	; and check if done
	GOTO	sub1		; no, carry on

	ADDWF	ADbin		; yes, add 100 back on
	DECF	Huns		; and correct loop count

; Calculate Tens digit......................................

	BSF	STATUS,C	; repeat process for Tens
	MOVLW	D'10'		; load 10
sub2	SUBWF	ADbin		; and subtract from result
	INCF	Tens		; count number of loops
	BTFSC	STATUS,C	; and check if done
	GOTO	sub2		; no, carry on

	ADDWF	ADbin		; yes, add 100 back on
	DECF	Tens		; and correct loop count
	MOVF	ADbin,W		; load remainder
	MOVWF	Ones		; and store as Ones digit

	RETURN			; done

⌨️ 快捷键说明

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