- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Hex to ASCII conversion in 8051
Now we will see how to convert Hexadecimal number to its ASCII equivalent using 8051. This program can convert 0-9 and A-F to its ASCII value.
We know that the ASCII of number 00H is 30H (48D), and ASCII of 09H is39H (57D). So all other numbers are in the range 30H to 39H. The ASCII value of 0AH is 41H (65D) and ASCII of 0FH is 46H (70D), so all other alphabets (B, C, D, E) are in the range 41H to 46H.
Here we are providing hexadecimal digit at memory location 20H, The ASCII equivalent is storing at location 30H.
Address | Value |
---|---|
. . . | |
20H | 0EH |
21H | |
. . . |
Program
MOVR0,#20H; Initialize the address of the data MOVA,@R0; Get the data from an address, which is stored in R0 MOVR2,A;Store the content of A into R2 CLRC; Clear the Carry Flag SUBBA,#0AH;Subtract 0AH from A JCNUM ; When a carry is present, A is numeric ADDA,#41H;Add41H for Alphabet SJMPSTORE; Jump to store the value NUM: MOVA,R2; Copy R2 to A ADDA,#30H; Add 30H with A to get ASCII STORE: MOVR0,#30H; Point the destination location MOV@R0,A; Store A content to the memory location pointed by R0 HALT: SJMPHALT
The logic behind HEX to ASCII conversion is very simple. We are just checking whether the number is in range 0 – 9 or not. When the number is in that range, then the hexadecimal digit is numeric, and we are just simply adding 30H with it to get the ASCII value. When the number is not in range 0 – 9, then the number is range A – F, so for that case, we are converting the number to 41H onwards.
In the program, at first, we are clearing the carry flag. Then subtracting 0AHfrom the given number. If the value is numeric, then after subtraction the result will be negative, so the carry flag will be set. Now by checking the carry status, we can just add 30H with the value to get ASCII value.
In other hands when the result of the subtraction is positive or 0, then we are adding 41H with the result of the subtraction.
Output
Address | Value |
---|---|
. . . | |
20H | 0EH |
21H | |
. . . | |
30H | 45H |
31H | |
. . . |
- Related Articles
- Conversion of four-digit hex to ASCII in 8051
- ASCII to hex and hex to ASCII converter class in JavaScript
- Binary to BCD conversion in 8051
- BCD to binary conversion in 8051
- 8085 Program to convert ASCII to HEX
- 8085 Program to convert HEX to ASCII
- Program to convert ASCII to HEX in 8085 Microprocessor
- Program to convert HEX to ASCII in 8085 Microprocessor
- Convert Hex to ASCII Characters in the Linux Shell
- 8085 Program to convert two-digit hex to two ASCII values
- Program to convert two-digit hex to two ASCII values in 8085 Microprocessor
- Conversion of Hex decimal to integer value using C language
- How to Convert Hex String to Hex Number in C#?
- Find the ASCII value of the uppercase character ‘A’ using implicit conversion in C language?
- Arithmetic group in 8051
