Convert 2 digit decimal to binary in 8051

Hello everybody,

I have two registers in my 8051:

R0 and R1 which represent a digit decimal number.

I need to convert it to a binary/hex number and place it in another register..

Was wondering if the following method would take care of it:

mov a,r0 ; take the units directly as it is to the LSB mov r7,a

mov a,r1 ; take the tens by mutliplying with #10D and mov b,#10 ; adding to the LSB mul ab add a,r7 mov r7,a

So would my r7 now have the binary equivalent of r0r1(decimal number)

Thank you, Methi

Reply to
methi
Loading thread data ...

As long as the original registers had binary values in them. If they had ascii characters then you would have to subtract 30h from them first.

Mike.

Reply to
NewsGroup

Hello...

Actually I am trying to convert the decimal to its hex value.....

Any suggestions

Thank you..

Methi

NewsGroup wrote:

Reply to
methi

You should do MOD 16 and if result > 9 do if = 10 => 'A' = 11 => 'B' = 12 => 'C' = 13 => 'D' = 14 => 'E' = 15 => 'F'

Mickey

P.S. Of coures this is just principle, you should write your own code

Reply to
Mickey

Hi,

Right now I am not exactly sure about what conversion I have to make...

Actually.... I am basically doing this:

I am moving #1 to #9 into my registers R0 and R1 depending on certain conditions..

Then I am moving the register values to the accumulator and subtracting #30h

Then displaying it on an LCD...

So I want the reverse of this being done...that is the values #1 to #9 in registers R0 and R1....basically represnting the units and tens of a

2 digit number....eg: 99 or 45 or 66...... to hex value...

So this is basically a ASCII to hex conversion right??

For eg: if my R0 has # 2 and my R1 and # 3

I want this value 32 to be converted to hex...

How can I do that?

Thank you,

Methi

Mickey wrote:

Reply to
methi

add an ASCII '0' to each 0x30h the LCD expects ASCII not binary. This assumes you are using a Hitachi based one.

Reply to
Neil Kurzman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.