Tuesday, May 31, 2016

8051 Program - 16 bit binary to asci

; | Purpose: Routine to convert a 16bit binary number in ASCII
; |
; | INPUT : R2 (Lsb) and R3 (Msb) ( binary)
; |
; | OUPUT : 30h,31h,32h,33h,34h (internal RAM address) (ASCII)
; | msb--^ ^------lsb
; |
; | Destroy all registers
; |
; | PROGRAMMER: Bruno Marcio Diogo Venancio ( bruno.marcio@bol.com.br )
; | BRAZIL 07/19/2002
; | THIS CODE CAN BE FREELY DISTRIBUTED WITHOUT CHANGES
BINTOASC:
MOV R0,#30h ; R0 = POUT
MOV DPTR,#TAB ; R <- TAB(P)
COM1:
CLR A ; P <- 0
MOVC A,@A+DPTR ; R = TAB(P)
MOV R7,A
INC DPTR
CLR A
MOVC A,@A+DPTR
MOV R6,A
MOV R4,#'0' ; C <- '0'
SOMA: ; N <- N-R
CLR C
MOV A,R2
SUBB A,R6
MOV R2,A
MOV A,R3
SUBB A,R7
MOV R3,A
JC SAIDA ; If < 0 goto SAIDA
INC R4 ; If > 0 then C <- C +1
SJMP SOMA ; goto SOMA
SAIDA:
MOV A,R4
MOV @R0,A ;TABOUT (POUT) <- C
MOV A,R2
ADD A,R6 ; N=N+R
MOV R2,A
MOV A,R3
ADDC A,R7
MOV R3,A
INC R0 ; PSAIDA=PSAIDA +1
CLR A
MOVC A,@A+DPTR
CJNE A,#1,INCREMENTA ; TAB(P) = 1 ?
RET ; If yes, END
INCREMENTA: ; If No, P <- P+1
INC DPTR
LJMP COM1 ; goto COM1
TAB:
DW 10000
DW 1000
DW 100
DW 10
DW 1



Related topics:
8051 Program - 16 bit hex to bcd   |   8051 Program - bcd byte   |   8051 Program - byte to ascii   |   8051 Program - 5 digit decimal to binary   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment