# PIC18f ASCII

#### Dritech

Joined Sep 21, 2011
835
Hi all,

I am using an ADC to display temperature on an LCD.(using assembly).

Can someone help me in separating a two character number and convert each character to ASCII ??

For example if the temperature is 25°C, separate 2 from 5 and convert them to ASCII (i.e. 00110010, 00110101)

Thanks.

#### t06afre

Joined May 11, 2009
5,934
What is your data material before conversion. Is it just a raw number from the ADC? That first need to be scaled and then converted to ASCII

#### Dritech

Joined Sep 21, 2011
835
Hi.
Thanks for the replies.

What is your data material before conversion. Is it just a raw number from the ADC? That first need to be scaled and then converted to ASCII
The input of the ADC will be from a PT1000 which is connected to an OP-AMP. The ADC is set to increment 1 bit for every degree (i.e. 1 degree = 00000001... 2 degree= 00000010 etc). Now i need to convert the mentioned output binary to ASCII. From 1 to 9 degree its no problem since all i have to do is add 48 to it, but when the value is with two digits (ex. 25degree) i have to separate 2 and add 48 to it and the same with 5.

I will read the tutorials which Markd77 gave and see if i manage to make it work.

Thanks.

#### Dritech

Joined Sep 21, 2011
835
Hi, thanks again Markd77. I managed to make it work with the help from the link you gave me.

The only problem is that i cannot understand how the binary is being converted to ASCII. Can someone explain the conversion routine (coding below) with comments please? I would appreciate it a lot.

Rich (BB code):
BIN2BCD

;---------------------

;in: BIN
;out huns. tens, ones

movlw 8
movwf count
clrf huns
clrf tens
clrf ones

movlw 5
subwf huns, 0
btfsc STATUS, C

movlw 5
subwf tens, 0
btfsc STATUS, C

movlw 5
subwf ones, 0
btfsc STATUS, C

decf count, 1
bcf STATUS, C
rlf BIN, 1
rlf ones, 1
btfsc ones,4 ;
CALL CARRYONES
rlf tens, 1

btfsc tens,4 ;
CALL CARRYTENS
rlf huns,1
bcf STATUS, C

movf count, 0
btfss STATUS, Z

movf huns, 0 ; add ASCII Offset
movwf huns

movf tens, 0 ; add ASCII Offset
movwf tens

movf ones, 0 ; add ASCII Offset
movwf ones

RETURN

movlw 3

RETURN

movlw 3

RETURN

movlw 3

RETURN

CARRYONES
bcf ones, 4
bsf STATUS, C
RETURN

CARRYTENS
bcf tens, 4
bsf STATUS, C
RETURN

#### t06afre

Joined May 11, 2009
5,934