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:
Search entire site for: 'Easy math solution'.

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

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

I receive a NMEA format string as the following:

                *              *

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?


1999\05\05@011359 by Regulus Berdin

picon face

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

;unpacked bcd*3
       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


       addlw   0x66
       addwf   INDF,f
       movlw   0x66
        andlw  0xF0
        andlw  0x0F
       subwf   INDF,f

;packed bcd multiply by 2 (untested)
       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

       rlf     bcd4
       rlf     bcd3
       rlf     bcd2
       rlf     bcd1


ICQ#:   31651436

Craig Lee wrote:
{Quote hidden}

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