Saturday, April 30, 2016

8051 Program – hex to ascii

; hex to ascii conversion
; input: 4000H
; output: 4001H-4002H
ORG 0H
HEX_ADDR EQU 4000H
ASCII_ADDR EQU 4001H
MAIN:
MOV DPTR,#HEX_ADDR ; fill memory
MOV A,#0FBH
MOVX @DPTR,A
LCALL CONV
SJMP MAIN
CONV:
MOV R7, #2
MOV DPTR,#HEX_ADDR
MOVX A,@DPTR
MOV B,A
ANL A,#0F0H
SWAP A
MOV R6,A
SJMP find
loop: MOV A,B
ANL A,#0FH
MOV R6,A
find: CLR C
SUBB A,#0AH
JC down ;if carry, jump to label down
MOV A,R6
ADD A,#37H;add 37 to a
sjmp store
down:MOV A,R6
ADD A, #30H;add 30h to a
store: INC DPTR;increment dptr
MOVX @DPTR,A ; move data from a to external memory location
DJNZ R7,loop
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 - ascii to hex   |   8051 Program - bcd to ascii   |   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