Reply
Highlighted
Posts: 81
Registered: ‎04-17-2005
Accepted Solution

16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Hi,
I want to convert a 16bit (2bytes HEX)data like03C2H to ASCII code ,then display it on char LCD.
How to program this in assembly?Is there routines or link about this?
Thanks in advance!
email:luckrock789@yahoo.com.cn
Posts: 8,176
Registered: ‎08-13-2003

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

How to program this in assembly
write the code. assemble it, link it, load it.

or do you mean where can I find the code?

Erik
erik
Posts: 81
Registered: ‎04-17-2005

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Hi,Erikm
Data convertion in assembly is an bother thing.
I think there must exit some routines
in the early 8051 decades.But I can't find it in GOOGLE.
Although I can write it on myself ,I am feeling it will take a long time, for I am only work it in spare time.
Thanks anyway, Your encouragement is aprreciated,But not suit me now.
Best Regards.
email:luckrock789@yahoo.com.cn
Posts: 6,327
Registered: ‎02-15-2004

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

8052 Code Library on 8052.com
Byte to ASCII

Tsuneo
Posts: 177
Registered: ‎02-10-2005

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

So Erikm -- did Mr. Luckrock789's reply to your input make you laugh?

If so: great! You are still with us!

If not: oooo -- lighten up my friend. Life is short and all of our stories end the same way eventually /!
Posts: 8,176
Registered: ‎08-13-2003

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

So Erikm -- did Mr. Luckrock789's reply to your input make you laugh?

it did and when I were about to post the link to the code library, Tsuneo had already done it
erik
Posts: 81
Registered: ‎04-17-2005

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Hi,Gentlemen
I would say you are always so kind,and thank you very much.Although the nibble routine is one byte Hex data convetion to ASCII(I will adjust it with the condition two bytes hex convertion).
Sir Isaac ,Newton have saidIf I have seen further ,it is by standing upon the shoulders of giants
Also Chinese famous dictum say thatDon't be abashed at asking unknown.
My best Regards.
email:luckrock789@yahoo.com.cn
Posts: 6,327
Registered: ‎02-15-2004

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

it did and when I were about to post the link to the code library, Tsuneo had already done it
Sorry Erik, I must learn patience.

Also Chinese famous dictum say thatDon't be abashed at asking unknown.
Also in Japan, Asking is a shame on a shot time, but not asking is a shame on whole life.

Tsuneo
Posts: 177
Registered: ‎02-10-2005

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Welcome to the closest we will ever get, here in the 21st century, to the fellowship of the ring. Information freely shared, in a spirit of good will. Perhaps there is hope for our species afterall /
Posts: 81
Registered: ‎04-17-2005

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Hi,Gentlemen:
Thanks for your continuous care.
As Reference the 8052 Web routines(Charlcd.asm),which are 3 bytes (24bit binary data) to ASCII conversation and One byte to ASCII conversation.In the past day,I wrote the 16bit Binary Data to ASCII conversation sub_routine suited for my projects , debug on the Hardware platform ,and prove it work now.
It can convert HEX data0360H to ASCII data864 on LCD .
Now Post it for share:
;*******************************************************************************
;Hex16ToASCII:
;converts a 16 bit binary number to a
;string of ASCII characters.
;*******************************************************************************

;Input:
;R6--low byte of the 16BIT hext data
;R5--hi byte
;output:
;R4-- 1'S dec nuber of ACII
;R3-- 10'S dec number of ASCII
;R2-- 100'S dec nuber of ASCII
;R1-- 1000'S dec number of ASCII
;R0-- 10000'S dec number of ASCII

;usage:
;clear R0,R1,R2,R3,R4
;mov R5,High BYTE of the data to be converted
;mov R6,Low byte of the data to be converted
;--------------------------------
Hex16ToASCII:
push PSW
push ACC

CLR C
MOV R0,#0 ;10,000 counter clear

Hex16ASCIILoop1:
MOV A,R6 ;16bit hex data - 10,000 (2710H)
SUBB A,#10H
MOV R6,A ;save left value

MOV A,R5
SUBB A,#27H
MOV R5,A

JC Hex16AsciiComp1
;if 16bit hex data< 10,000,jump to skip1

INC R0 ;else save 10,000s counter
jmp Hex16ASCIILoop1
;again:16bit hex data - 10,000 (2710H)

Hex16AsciiComp1:
;here is the compensation at condition
;16bit hex data< 10,000
;because we have subtrate it with 10,000
;so add 10,000

;get the 1,000s',100s',10s',1s' value to R5R6
MOV A,R6
ADD A,#10H
MOV R6,A
MOV A,R5
ADDC A,#27H
MOV R5,A
CLR C
;End of the compensation
MOV R1,#0 ;1,000 counter clear

Hex16ASCIILoop2:
;subtrate the left data by 1,000(3E8)
;repeatedly,until R5R6<1,000
MOV A,R6
subb A,#0E8H
mov R6,A

MOV A,R5
subb A,#03H
MOV R5,A

JC Hex16AsciiComp2
;the left R5R6 <1,000,jump to compesation 2

INC R1 ;else save the 1,000 counter R1
jmp Hex16ASCIILoop2

Hex16AsciiComp2:
;Compensate because subbtrate 1000 from R5R6
;at the condition R5R6<1000
MOV A,R6
ADD A,#0E8H
MOV R6,A

MOV A,R5
ADDC A,#03H
MOV R5,A
CLR C

MOV R2,#0
;100S' counter clear

Hex16AsciiLoop3:
;the 100s' (64H)condition
mov A,R6
SUBB A,#64H
mov R6,A

MOV A,R5
subb A,#0

JC Hex16AcsiiComp3
INC R2
jmp Hex16AsciiLoop3
Hex16AcsiiComp3:
mov A,R6
ADD A,#64H
MOV R6,A
MOV A,R5
ADDC A,#0
MOV R5,A

CLR C
MOV R3,#0
;10S' counter clear
Hex16AsciiLoop4:
;10S' CONDITION, (R5 =0,so despite it)
mov A,R6
SUBB A,#0AH
MOV R6,A

JC Hex16AsciiComp4
INC R3
jmp Hex16AsciiLoop4
Hex16AsciiComp4:

add A,#0AH
MOV R6,A
;here R6 represent 1S'
mov R4,a
;1S' counter ->R4

;NOW R4,R3,R2,R1,R0 all add 30H,to get real
;ASCII code
clr c

mov A,R4
addc A,#30H
MOV R4,A

MOV A,R3
ADD A,#30H
MOV R3,A

MOV A,R2
ADD A,#30H
MOV R2,A

MOV A,R1
ADD A,#30H
MOV R1,A

MOV A,R0
ADD A,#30H
MOV R0,A
pop PSW
pop ACC
RET
;END OF CONVERATION ROUTINE.
;=========================================


That's it.
My Best Regards To You ALL.
email:luckrock789@yahoo.com.cn
Posts: 177
Registered: ‎02-10-2005

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Thanks for posting your code Luckrock789. I've added it to my library file for future use.

In the Western tradition, we say Privilege the question. This is a coded way of saying that _asking_ questions is more important (or valuable), in the end, than _answering_ them. We (in the west) have come to this conclusion only lately (20th Century). Your tradition (and Tsueneo's) have this wisdom from long ago...

But of course, all that doesn't have much to do with 8051s or Silabs / Important though, in the ultimate scheme of things...
Posts: 2
Registered: ‎07-19-2011

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

@ luckrock789....
Thanks 4 the nice code..... But it seems to have some logical errors in it....

Firstly, What's the need of push and pop instructions as it changes the whole scenario of the working of the code ???

Secondly, there is one big blunder in your code which keeps the loop infinitely running. So, we got no results.
The solution is to add one more instruction after subb A,#0

Hex16AsciiLoop3:
;the 100s' (64H)condition
mov A,R6
SUBB A,#64H
mov R6,A

MOV A,R5
subb A,#0

/ / MOV R5,A
Posts: 2
Registered: ‎07-19-2011

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

@ luckrock789....
Thanks 4 the nice code..... But it seems to have some logical errors in it....

Firstly, What's the need of push and pop instructions as it changes the whole scenario of the working of the code...

Secondly, there is one big blunder in your code which keeps the loop infinitely running. So, we got no results.
The solution is to add one more instruction after subb A,#0

Hex16AsciiLoop3:
;the 100s' (64H)condition
mov A,R6
SUBB A,#64H
mov R6,A

MOV A,R5
subb A,#0

/ / MOV R5,A
Posts: 173
Registered: ‎11-25-2007

Re: 16bit data(2 bytes Hex) convert to ASCII and Display on LCD

Hey IronMan, your clock is about six years slow.