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.
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
You need a binary to BCD routine, there are a few here. To get to ASCII just add the value of ASCII "0". Best to check they work by running a few numbers through them. http://www.piclist.com/techref/microchip/math/radix/index.htm
Hi. Thanks for the replies. 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.
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. Thanks in advance. Code ( (Unknown Language)): BIN2BCD ;--------------------- ;in: BIN ;out huns. tens, ones ;uses ADD-3 algoerthm movlw 8 movwf count clrf huns clrf tens clrf ones BCDADD3 movlw 5 subwf huns, 0 btfsc STATUS, C CALL ADD3HUNS movlw 5 subwf tens, 0 btfsc STATUS, C CALL ADD3TENS movlw 5 subwf ones, 0 btfsc STATUS, C CALL ADD3ONES 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 GOTO BCDADD3 movf huns, 0 ; add ASCII Offset addlw h'30' movwf huns movf tens, 0 ; add ASCII Offset addlw h'30' movwf tens movf ones, 0 ; add ASCII Offset addlw h'30' movwf ones RETURN ADD3HUNS movlw 3 addwf huns,1 RETURN ADD3TENS movlw 3 addwf tens,1 RETURN ADD3ONES movlw 3 addwf ones,1 RETURN CARRYONES bcf ones, 4 bsf STATUS, C RETURN CARRYTENS bcf tens, 4 bsf STATUS, C RETURN
Se if this AN can be of any help http://ww1.microchip.com/downloads/en/AppNotes/00526e.pdf http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011000