sangmeshwar
Junior Member level 3
Please give detail 8051 microcontroller program for converting ASCII code into HEX.
Thanks
Sangmeshwar
Thanks
Sangmeshwar
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
; ==============================================
; ASCII_Hex conversion routine...
ASC_Hex: CJNE A, #'0', Ch_1 ; Test for ASCII numbers..
Ch_1: JC Ch_Bad ; Character is less than a '0'..
CJNE A, #'9'+1, Ch_2 ; Test value range..
Ch_2: JC Ch_Val_109 ; Character is between 0 and 9..
CJNE A, #'A', Ch_3 ; Test for upper case hex letter..
Ch_3: JC Ch_Bad ; Character is less than 'A'..
CJNE A, #'F'+1, Ch_4 ; Test value range..
Ch_4: JC Ch_Val_AF ; Character is between A and F..
Ch_Bad: SETB ErrFlag5 ; Character is not a Hex number..
LJMP ASC_Hex_Exit
Ch_Val_AF: CLR C
SUBB A, #07h
Ch_Val_109: CLR C
SUBB A, #'0'
CLR ErrFlag5
ASC_Hex_Exit:RET
; ===================================================
; ***************************************************
; * ASCII to HEX *
; * takes an ascii character and converts it to hex *
; ***************************************************
;
ASCIItoHEX:
setb ACC.5 ; Strip case, lower case ascii
subb a,#0x57 ; value a - f will not carry
jnc ASCIIDone ; if not carry then we have converted the nibble
add a,#0x27 ; Convert back to 0 - 9
ASCIIDone:
ret