Searching \ for 'Easy math solution' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=math
Search entire site for: 'Easy math solution'.

Truncated match.
PICList Thread
'Easy math solution'
1999\05\04@124954 by Craig Lee

flavicon
face
I am looking for an easy math solution for this problem:

I receive a NMEA format string as the following:

$GPGGA,165445.71,3322.8863123,N,11156.5499123,W,2,3,001.8,,M,-027,M,1,0777*7
6
                *              *

The two marked strings are latitude and longitude.

33 degrees 22 minutes and the rest is fraction of minutes.

What I need to do is convert the fraction of minutes to seconds
and hundredths of seconds, then convert back to a string.

So my thought is to convert 886312 to a number then take
(886312 X 60)/1000 to give me 53178 then I convert that to
ASCII do a test on the low char to see if it is less than 5
and display 53.17 or 53.18

I am using a 16F84 with C that is of course resource lean....

Is this the best way?

Craig

1999\05\05@011359 by Regulus Berdin

picon face
Hi,

Converting the string to binary then multiplying it again then covert
again to bcd/string can use more resources.  What you need is a bcd
multiply by 6, this can be done by multiplying by 3 then by 2.

Here are some useful routines that you can use, implementing them is
trivial:

;unpacked bcd*3
bcd3x:
       movlw   i
       movwf   8

       movlw   bcd7
       movwf   FSR
       clrf    carry           ;no carry yet
       goto    foo

loopf   swapf   INDF,w
       movwf   carry
       movlw   0x0F
       andwf   carry,f         ;clear upper nibbles
       andwf   INDF,f
       decf    FSR,f           ;next digit

foo     movf    INDF,w          ;bcd*3
       movwf   tmp
       call    add_bcd
       movf    tmp,w
       call    add_bcd

       movf    carry,w         ;add carry
       call    add_bcd

       decfsz  i,f
        goto   loopf

       return

add_bcd:
       addlw   0x66
       addwf   INDF,f
       movlw   0x66
       skpndc
        andlw  0xF0
       skpnc
        andlw  0x0F
       subwf   INDF,f
       return

;------------------------------------
;packed bcd multiply by 2 (untested)
bcd2x:
       movlw   0x33
       addwf   bcd1
       addwf   bcd2
       addwf   bcd3
       addwf   bcd4

       movlw   0x03
       btfss   bcd1,3
        subwf  bcd1
       btfss   bcd2,3
        subwf  bcd2
       btfss   bcd3,3
        subwf  bcd3
       btfss   bcd4,3
        subwf  bcd4

       movlw   0x30
       btfss   bcd1,7
        subwf  bcd1
       btfss   bcd2,7
        subwf  bcd2
       btfss   bcd3,7
        subwf  bcd3
       btfss   bcd4,7
        subwf  bcd4

       clrc
       rlf     bcd4
       rlf     bcd3
       rlf     bcd2
       rlf     bcd1

regards,
Reggie

--
e-mail: spam_OUTrberdinTakeThisOuTspambigfoot.com
ICQ#:   31651436
URL:    http://www.bigfoot.com/~rberdin


Craig Lee wrote:
{Quote hidden}

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