; BCD to ASCII
; To convert packed BCD to ASCII,
; it must first be converted to to unpacked BCD.
; Then the unpacked BCD is tagged with 30h.
; 4000H = 45H bcd
; 4001H = 34H ascii
; 4002H = 35H acsii
ORG 0H
ADDR EQU 4000H
BCD EQU 45H
MAIN:
MOV A, #BCD
MOV DPTR,#ADDR ;fill memory with bcd
MOVX @DPTR, A
LCALL CONV
SJMP MAIN
CONV:
MOV DPTR,#ADDR ;load addr into dptr register
MOVX A,@DPTR ;move the content of location addr to a
MOV R2,A ;move the data from a to r2
ANL A,#0F0H ;and a with 0f0h
SWAP A ;swap a
ORL A,#30H ;or a with 30h
INC DPTR ;increment dptr
MOVX @DPTR,A ;move the data from a to memory location
MOV A,R2 ; move the data from r2 to a
ANL A,#0FH ; and a with 0fh
ORL A,#30H ;or a with 30h
INC DPTR ;increment dptr
MOVX @DPTR,A ;move the data from a to memory location
RET
END
; bcd to ascii
; input R1
ORG 0H
MOV R1,#23 ;Input char
LCALL CONV
SJMP $
CONV:
MOV A,R0
ANL A,#0Fh
ADD A,#30h
MOV R1,A ;ASCII(FIRST DGT)
MOV A,R0
ANL A,#0F0h
SWAP A
ADD A,#30h
MOV R2,A ;ASCII(SECOND DGT)
RET
END
Related topics:
8051 Program - decimal to hex | 8051 Program - hex to decimal 8bit | 8051 Program - decimal to ascii | 8051 Program - ascii to decimal | 8051 Program - hex to ascii | 8051 Program - ascii to hex | 8051 Program - ascii to bcd | 8051 Program - bcd to hex 8bit | 8051 Program - hex to bcd 8bit | 8051 Program - hex to bcd 12bit | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment