Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

hex to decimal and then to ascii

Status
Not open for further replies.

garg29

New Member
dear friends
can anybody help me out for coding in assembly to convert hex to decimal and then decimal back to ascii for 8051 microcontroller.i am designing a temperature controller and taking display on lcd.

please do help

thanks
amit
 
CODE

HEX to ASCII
Code:
MOV R6, #00H;
MOV A, Count;
MOV B, A;
ANL A, #0FH;
DA A;
MOV R7, A;
MOV A, B;
ANL A, #0F0H;
SWAP A;
JZ LOOP1;
MOV B, A;
CLR A;
LOOP3: ADD A, #16H;
DA A;
JNC LOOP2
INC R6;
LOOP2: DJNZ B, LOOP3;
LOOP1: ADD A, R7;
DA A;
JNC LOOP4
INC R6;
LOOP4: MOV B, A;
ANL A, #0FH;
ADD A, #30H;
MOV i, A;
MOV A, B;
SWAP A;
ANL A, #0FH;
ADD A, #30H;
MOV j, A;
MOV A, R6;
ADD A, #30H;
MOV k, A;
MOV A, B;
MOV B, R6;
Try to study the logic of this code and try to write one for your own application. But hope this will prove fine working to your application. The Count is the hex no. which suppose you want to convert. Then the output will be 3 different numbers which are nothing but the ASCII representation of the corresponding no. For 8 bit ADC this code is good enough. As (FF)16 can be converted in (255)10 and then the output is 32h, 35h, 35h. i,j,k are the variables, you can use any RAM location at the place of i,j,k. i = LSB and k = MSB.
 
Status
Not open for further replies.

Latest threads

Back
Top