8051 program to convert Ascii value to Hexadecimal value….

Hi guys…In this article let’s learn conversion.The ascii to Hex conversion logic is very simple.The hexadecimal numbers from 31H-39H are 0-9 numbers in ascii and
41H to 46H are A to F numbers. So we should first compare the number with 40H if it is lesser subtract with 30H and it is greater subtract with 37H.

Asciivalue             Hexadecimal value
31H             01H
32H             02H
33H             03H
34H             04H
35H             05H
36H             06H
37H             07H
38H             08H
39H             09H
41H             0AH
42H             0BH
43H             0CH
44H             0DH
45H             0EH
46H             0FH


Algorithm:

1)Initialize R0 with number which is required to find equivalent Hexadecimal number code.
2)Compare it with 40H and jump to label1 if it is equal.
3)Compare the carry bit to find which is greater and lesser.
4)If the carry bit is not set(it implies it is greater)jump to label2.
5)If it is lesser subtract the number with 30H.
6)If it is greater subtract the number with 37H.

Code goes here:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisment ad adsense adlogger