# PICMicrocontoller Radix MathMethod

## Binary to ASCII, 16 bit to 5 digits (1 at a time) no temp register (!)

```;Thanks Scott, your code is very instructive.
;Total execution time:
;worst case: 47 + 66 + 58 + 39 + 2 = 213 cycles(with known zero)
;worst case: 53 + 73 + 58 + 39 + 2 = 226 cycles(without known zero)

;Code size: 68

clrf temp
sub30k
movlw 3
movlw low(30000)
subwf Lo, f

IFNDEF known_zero
movlw high(30000)
skpc
movlw high(30000) + 1
subwf Hi, f
ELSE
rlf known_zero, w
sublw high(30000) + 1
subwf Hi, f
ENDIF
skpnc
goto sub30k

decf temp, f
movlw low(10000)

IFNDEF known_zero
movlw high(10000)
skpnc
movlw high(10000) + 1
ELSE
rlf known_zero, w
ENDIF
skpc
;       Output(temp)         ;output temp = TenK
;worst case: 10 * 3 + 9 * 3 - 1 = 47 (with known zero)
;worst case: 11 * 3 + 10 * 3 - 1 = 53 (without known zero)

clrf temp
sub3k
movlw 3
movlw low(3000)
subwf Lo, f
IFNDEF known_zero
movlw high(3000)
skpc
movlw high(3000) + 1
subwf Hi, f
ELSE
rlf known_zero, w
sublw high(3000) + 1
subwf Hi, f
ENDIF
skpnc
goto sub3k
decf temp, f
movlw low(1000)

IFNDEF known_zero
movlw high(1000)
skpnc
movlw high(1000) + 1
ELSE
rlf known_zero, w
ENDIF
skpc
;       Output(temp)         ;output temp = Thou
;worst case: 10 * 4 + 9 * 3 - 1 = 66 (with known zero)
;worst case: 11 * 4 + 10 * 3 - 1 = 73 (without known zero)

clrf temp
sub300
movlw 3
movlw low(300)
subwf Lo, f
IFNDEF known_zero
movlw high(300)
skpc
movlw high(300) + 1
subwf Hi, f
ELSE
rlf known_zero, w
sublw high(300) + 1
subwf Hi, f
ENDIF
skpnc
goto sub300
movlw 100
decf temp, f
skpc
incf Hi, f
btfsc Hi, 7
;       Output(temp)         ;output temp = Hund
;worst case: 10 * 4 + 5 * 3 + 3 = 59

clrf temp
movlw 30
sub30
incf temp, f
subwf Lo, f
skpnc
goto sub30
movfw temp
rlf temp, f
movlw 10
decf temp, f
skpc
;       Output(temp)         ;output temp = Tens
;worst case: 5 * 4 + 5 * 3 + 4 = 39

;       Output(Lo)         ;output temp = Ones

```

Questions:

• spammrken88 at ~NOSPAM~gmail.com asks:
I am new to PIC, so I apologise in advance for this question.

I am trying to get the ten-bit number from a 16F877a's A/D convertor to a computer using Hyperterminal, so this code converts the binary ADC value into an ASCII decimal, I assume?

I am using MPASM to programme the code, and understand the basics. What I do not understand is the numbers in brackets after movlw. Do I take out the "high"/"low" before it?

Also, since the ADC is only 10-bit, can the first section of the code "Output(temp) ;output temp = TenK" be discarded?

Thank you in advance!
James Newton replies: If I remember correctly, high() takes the upper 8 bits of the value and low() takes only the lower 8 bits.

Yes, you can safely remove the TenK output.+

+

• spammrken88 at ~NOSPAM~gmail.com
Thank you for the reply!

How about the Hi and Lo variables? I thought those two would be high and low bytes of the binary number...
I assembled the unedited code with MPASM and it seemed to have assembled fine.

My second question was not too clear; sorry! I meant whether I can take out the entire code from the beginning up to the TenK output. If I do that, would it affect the last four digits?

Thank you very much!
James Newton replies: Try it and see! Let us know the result? Ken of Operation Radiation replies: To answer my own question from a long time ago, it does not work. Anyways, the result is not actually in ASCII, but in decimal. One needs to add 0x30h or .48 to the output digits to obtain the ASCII result. Thank you Nikolai for the great code!+

+

+

 file: /Techref/microchip/math/radix/b2a-16b4a-ng.htm, 5KB, , updated: 2005/11/4 22:22, local time: 2020/6/1 06:45, TOP NEW HELP FIND:  34.204.176.125:LOG IN

 ©2020 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! PIC Microcontoller Radix Math Method

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here:
if you want a response, please enter your email address:
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

.