Searching \ for '[PIC]: hex2dec' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'hex2dec'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: hex2dec'
2000\12\23@130641 by Drew Vassallo

picon face
Scott (and anyone else),

The hex2dec ascii routine at
http://204.210.50.240/techref/microchip/math/radix/b2a-16b5a-rl.htm

Seems to be tough to get working.  I changed instances of the "skp" command
to "goto $+2" and have a known zero value.

I resolved the "movlw 10000 & 255" to "movlw 0x10" and the "sublw
(10000>>8)+1" to "movlw 0x28".  Also, changed the "movlw 1000 & 255" to
"movlw 0xE8" and the "addlw 1000>>8" to "addlw 0x03".  I believe these are
correct.

However, when I get to the "add1K" section, it runs through quicker than it
should and gives me useless values for the hundreds, tens, and ones.

Has anyone noticed this?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



'[PIC]: hex2dec'
2001\01\12@120107 by Drew Vassallo
picon face
No, I'm sure it doesn't work.  I tried everything, including having a
non-zero defined number and a known_zero - both.  Also, I used the original
decimal numbers and converted numbers - neither worked.

As for an example, try a number of 0x2700 (should be 9984d) put into HI and
LO.

I get outputs of 00, 09, 05, FD, and ?? (don't recall)
instead of 00, 09, 09, 08, and 04.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\01\13@024456 by Nikolai Golovchenko

flavicon
face
The corrected version is attached below. There was really just
one bug - skpc instead of skpnc in sub100 section, and some
syntax violations. Now it works with and without the known_zero reg.

Nikolai

;-------------------------------------------------------------------
#include <p16f84.inc>

;define something for output(x), or replace it with other code
#define output(x) movfw x

       cblock 0x0C
       temp
       LO, HI
       known_zero
       endc

;0x2700 = 9984
       movlw 0x27
       movwf HI
       movlw 0x00
       movwf LO
#IFDEF known_zero
       clrf known_zero
#ENDIF

; by Rich Leggitt with tweaks by Scott Dattalo and bugfix by Dmitry Kiryashov and Nikolai Golovchenko
; given 16 bit data in HI and LO, extract decimal digits
; requires one Output register called temp, HI and LO are destroyed.
; 42 instructions and less than 269 (or 252 with known_zero) instructions executed
       clrf temp
       goto $+2                ;[NG] was: skip
sub10k  incf temp,f
       movlw 10000 & 255
       subwf LO,f

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]
#IFNDEF known_zero
       movlw 10000 >> 8
       skpc
       movlw (10000>>8)+1      ;[NG] was: addlw 1     ; this sucks
       subwf HI,f
#ELSE
       rlf     known_zero,W
       sublw   (10000>>8)+1    ;bugfix by Dmitry Kiryashov and Nikolai Golovchenko
       subwf   HI,F
#ENDIF
       bc sub10k               ;9*7=63/8*7=56 inst in loop for 60900 (worst)
       output(temp);

       movlw 10
       movwf temp
add1k   decf temp,f
       movlw 1000 & 255
       addwf LO,f

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]
#IFNDEF known_zero
       movlw 1000 >> 8
       skpnc
       movlw (1000>>8)+1       ;[NG] was: addlw 1
       addwf HI,f
#ELSE
       rlf   known_zero,w
       addlw 1000 >> 8
       addwf HI,f
#ENDIF
       bnc add1k               ;9*10=90/8*10=80 inst in loop for 60900
       output(temp);

;Scott takes over here
       clrf  temp
       movlw 100
       goto $+2                ;[NG] was: skip
sub100
       incf  temp,f
       subwf LO,f
       skpnc                   ;[NG] was: skpc
       goto sub100

       decf  HI,f
       btfss HI,7              ;Check msb instead of carry for underflow.
       goto sub100             ;4 inst per loop to 200 then 7 per loop to 900.
                               ;Total 64(?) in loop for worst case

;at this point, HI = 0xff, and  0 <= LO <= 99

       output(temp)

       movlw 10
       movwf temp
add10   decf temp,f
       addwf LO,f
       bnc add10               ;40 inst in loop for worst case.
       output(temp);
       output(LO);
       return
;-------------------------------------------------------------------

---- Original Message ----
From: Drew Vassallo <spam_OUTsnurpleTakeThisOuTspamHOTMAIL.COM>
Sent: Friday, January 12, 2001 19:01:07
 To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
Subj: [PIC]: hex2dec

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...