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.

help with converting numbers to letters in 8051 assembly

Status
Not open for further replies.

Greital

New Member
hi,
I'm trying to complete my project in assembly 8051 , and thanks to all of you I completed the 1st phase
now I'm stuck in the 2nd phase

I should convert a number to its letters --->> for example if I put R3 = #31 it should print thirty one

I know I had to make an arrays:
1. single digit (one to nine)
2. double digit (eleven to nineteen)
3. tens digit (ten , twenty, thirty, ..........., ninety)

since the range from 1 - 99

and I know this function involve with division , but I don't know how to begin with it and check for each state

I need an explanation for the procedures ---> so please don't think I came here just to have the code

if the code is provided it will help alot, but if not it's ok since I need to understand it
 
Hi Greital! I try to help but you don't seem to give feedback!! You didn't respond to my last help... There are exmples in my article list... R3 = #31 will only print ascii '1' if you are in hex radix otherwise use R3 = #31h or R3 = #0x31..

As for printing ascii representation of numbers.. Take 0~999:

out (number / 100) + 0x30
out (number%100)/10 + 0x30
out (number % 10)

% = modulus.... When dividing AB.. A holds the Number and B holds the modulus!!
 
I'm really sorry for that, I just saw it after your reply to this thread :(
alot of things I need to do at the same time :banghead: --->>> I hope you can accept my apology :sorry:

thanks for your reply
I know I should divide and A holds the number an B the remain (module)
but what is the next step , how I can pick a specific string from the ROM of the specific number I put in R3 for example

please any help is appreciable and forgive me for what happen last time :sorry:
 
So what do you need to do... The last thread was a prime number sort!!

If you want to print a number from 0~99 its very easy on the 8051..

R3 holds a number.. R2 and R1 reserved for 10 and unit

move R3 into A
move 10 into B
then DIV AB

Add 0x30 to A and store in R2
Move B int A and add 0x30 then store in R1.

Code:
  $MOD51
   ORG  0
     JMP  START

START:
   MOV R1,#0     ; clear result
   MOV R2,#0     ;
   MOV R3,#56     ; Pick a number
   MOV A,R3
   MOV B,#10
   DIV AB       ; Split count
   ADD A,#0x30     ; ASCII -> R1
   MOV R1,A
   MOV A,B
   ADD a,#0x30     ; ASCII -> R2
   MOV R2,A
   
DONE:   JMP DONE

END
 
thanks for your reply, appreciate it :)
in this phase I have to show a number stored in R3 for example as letters
for example if I put R3=#31 ---> it should print thirty one in the LCD -->> I don't know how to generate the letters out of the numbers :banghead: that's my problem :arghh:

in your code, which part is involved getting the letters from the ROM for the number provided :confused: ??
 
Hi,
In the code results are stored in R1 (tens) and R2,(units) all are in ASCII format it is not numerical i.e., R1 holds #35 and R2 holds #36 ( it is not 5 tens and 6 units) in the ASCII table 0 to 9 equals to 30 to 39 in the ASCII format. Now if you already made LDC initialization, it is very easy to show content of R1,R2 LCD like this

MOV LCD_data_port,R1 ; tens first
MOV LCD_data_port,R2 ; the units first
the above data transfer only as data not as command
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top