Saturday, April 30, 2016

8051 Program – ascii to hex

ASCII codes 30 to 39 represent 0 to 9 in binary and 41 to 46 represent A to F. Therefore if the ASCII code is between 30-39h then 30h is subtracted from the code. If the number lies between A to F then 37h is subtracted from the code to get its binary equivalent.
; ascii to hex conversion
; input: 4000H
; output: 4001H
ORG 0H
ASCII_ADDR EQU 4000H
HEX_ADDR EQU 4001H
MAIN:
MOV DPTR,#ASCII_ADDR ; fill memory
MOV A,#0AH
MOVX @DPTR,A
LCALL CONV
SJMP MAIN
CONV:
MOV DPTR,#ASCII_ADDR
MOVX A,@DPTR
MOV R0,A
SUBB A,#0AH
JNC loop1
MOV A,R0
ADD A,#30H
SJMP loop
loop1: MOV A,R0
ADD A,#37H
loop: MOV DPTR,#HEX_ADDR
MOVX @DPTR,A
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 - 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