• PicŪ Basic

  • Converting GPS Data

    The following code example processes data from the NMEA sentences transmitted by GPS modules.

    You will first have to extract the data from the NMEA sentence using this code.

    Example 1 - convert GPS data to a MAIDENHEAD Grid Locator reference

    Once you have read and extracted the location data from a GPS string use this code to convert it to MAIDENHEAD Grid Locator referance (i.e. KL28PE ).

    Device 16F876
    ; MAIDENHEAD Grid Locator
    ;================================================= ===================================
    ;USE: After you successfully read the GPS Data via LES's GPS Parsing routine example
    ; then just make a GOSUB Maidenhead which allows you to get the needed characters
    ; and digits used to express a MAIDENHEAD Grid Locator (i.e. KL28PE ).
    ;================================================= ===================================
    ;--- LES's Parse GPS demo Dims ------------------------------------------------------
    Dim LATITUDE_DEGREES As Byte ;if those are allready declared in your code
    Dim LATITUDE_MINUTES As Byte ;namely LES GPS Parsing routine
    Dim LATITUDE_SECONDS As Word ;then kindly remove them from here
    ;---- MAIDENHEAD Dims ---------------------------------------------------------------
    Dim lat1 As Float
    Dim lat2 As Float
    Dim lat3 As Byte
    Dim lat4 As Byte
    Dim lat5 As Byte
    Dim lon1 As Float
    Dim lon2 As Byte
    Dim lon3 As Byte
    Dim lon4 As Byte
    Dim lon5 As Float
    Dim lon5b As Byte
    Dim let1 As Byte
    Dim let2 As Byte
    Dim let3 As Byte
    Dim let4 As Byte
    Dim let5 As Byte
    Dim let6 As Byte
    Dim llon2 As Byte
    Dim llat3 As Byte
    Dim llon3 As Byte
    Dim llat4 As Byte
    Dim llon5 As Byte
    Dim llat5 As Byte
    '----- Subroutine -------------------------------------------------------------------
    lat1 = LATITUDE_SECONDS / 3600
    lat1 = lat1 + LATITUDE_MINUTES / 60
    lat1 = lat1 + LATITUDE_DEGREES
    lat1 = 90 + lat1 ; (+) if NORTH only - else (-) insert your code here for N or S comparison
    ;lat1 = 90 - lat1 ; use like that for South
    lat3 = Abs (lat1 /10) ;used for second letter
    lat4 = lat3 * 10 ;
    lat4 = Abs (lat1 - lat4); used for second digit OK
    lat2 = lat1 - (lat3 * 10) ;
    lat2 = lat2 - lat4 ;
    lat5 = Abs (lat2 * 24) ; used for forth letter
    lon1 = LONGITUDE_SECONDS / 3600 ;
    lon1 = lon1 + LONGITUDE_MINUTES / 60 ;
    lon1 = lon1 + LONGITUDE_DEGREES ;
    lon1 = 180 + lon1 ; (+) if EAST only - else (-) insert your code here for E or W comparison
    ;lon1 = 180 - lon1 ; use like that for West
    lon2 = lon1 / 20 ; first letter
    lon3 = lon2 * 20 ;
    lon3 = Abs ((lon1 - lon3)/2) ; first digit
    lon4 = lon1 ;
    lon4 = lon4 // 2 ;
    lon5 = 20 * lon2 ;
    lon5b = lon1 ;
    lon5 = lon1 - lon5b ;
    lon5 = Abs ((lon5 + lon4)* 12); third letter
    lon5b = lon5 ; if these lines should be removed then change accordingly
    llon2 = lon2 ; the next LOOKUPL variables, but
    llat3 = lat3 ; the main purpose for them is to transfer the integer part of a floating
    llon3 = lon3 ; variable into a word or byte variable. Can be done also differently but
    llat4 = lat4 ; we don't discuss that here
    llon5 = lon5b;
    llat5 = lat5 ;
    let1 = LookUpL llon2 , ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"] ;1st character position 1
    let2 = LookUpL llat3 , ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"] ;2nd character position 2
    let3 = LookUpL llon3 , ["0123456789"] ;1st digit position 3
    let4 = LookUpL llat4 , ["0123456789"] ;2nd digit position 4
    let5 = LookUpL llon5 , ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"] ;3rd character position 5
    let6 = LookUpL llat5 , ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"] ;4th character position 6
    contributed by Les Johnson
  • Recent Activity



    Thread Starter: normnet

    Coming soon a new IDE: FineLineIDE! Features include:<O:p</O:p Bracket lines linking If-Endif, For-Next etc.<O:p</O:p Tabbed explorer so...

    towlerg Yesterday, 13:36 Go to last post

    Compiler issue with 16F1829 and I2C-LCD

    Thread Starter: Henk57

    Spend this afternoon with a compiler issue; no error's, but my LCD give only first line with squares, no characters, nothing. If I flash an old .hex...

    Henk57 Yesterday, 19:31 Go to last post

    CData Table

    Thread Starter: Beginner

    Is there perhaps the possibility to extend the IDE with a 'Raw Flash' command? Currently I have the huge problem that if I want to program a web page...

    hadv215 Yesterday, 22:41 Go to last post

    Pulse counter using COUNTER command

    Thread Starter: amod

    How I can use counter command for counting pulses on portd.3 of 16f877A.Iam making a 8 digit object counter.

    Henk57 Yesterday, 19:43 Go to last post