Gps with 16f628


Closed Thread
Results 1 to 8 of 8

Thread: Gps with 16f628

  1. #1
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166

    Default Gps with 16f628

    i am trying to display some gps data on an lcd screen. i have set up the screen to display the info i need, and i have got the info i want to display in each field, but when i start the system, i just get a two digit # displayed and not the info i want..


    here is an example of the data string that i want to be able to display parts of....

    eg1. $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,1 30998,011.3,E*62
    eg2. $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,1 91194,020.3,E*68


    225446 Time of fix 22:54:46 UTC
    A Navigation receiver warning A = Valid position, V = Warning
    4916.45,N Latitude 49 deg. 16.45 min. North
    12311.12,W Longitude 123 deg. 11.12 min. West
    000.5 Speed over ground, Knots
    054.7 Course Made Good, degrees true
    191194 UTC Date of fix, 19 November 1994
    020.3,E Magnetic variation, 20.3 deg. East
    *68 mandatory checksum

    and here is the code i am using for my display.


    @ DEVICE HS_OSC
    DEFINE OSC 10
    cmcon = 7
    TRISA = %00000000



    'variables
    '-------------------------------------------------------------
    lcd VAR PORTA.3
    gps VAR PORTB.0
    b0 VAR WORD
    b1 VAR WORD
    b2 VAR WORD
    b3 VAR WORD
    b4 VAR WORD
    b5 VAR WORD
    b6 VAR WORD
    b7 VAR WORD
    b8 VAR WORD
    b9 VAR WORD
    b10 VAR WORD
    b11 VAR WORD
    b12 VAR WORD

    'setup serial lcd
    '-------------------------------------------------------------

    Pause 5000
    SerOut2 lcd, 32,[254,"X"] 'clear screen
    Pause 100
    SerOut2 lcd, 32,[254,"X"] 'clear screen again
    SerOut2 lcd, 32,[254,"P",100] 'change resolution
    Pause 100
    SerOut2 lcd, 32,[254,"G",1,1] 'set home point
    SerOut2 lcd, 32,["WAYPOINT-"]
    SerOut2 lcd, 32,[254,"G",1,2] 'set home ON 2nd line
    SerOut2 lcd, 32,["N "]
    SerOut2 lcd, 32,[254,"G",11,2] 'set home on 2rd line
    SerOut2 lcd, 32,["W "]
    SerOut2 lcd, 32,[254,"G",1,3] 'set home on 3th line
    SerOut2 lcd, 32,["Speed- "]
    SerOut2 lcd, 32,[254,"G",11,3] 'set home on 3th line
    SerOut2 lcd, 32,["Alt- "]
    SerOut2 lcd, 32,[254,"G",1,4] 'set home on 4th line
    SerOut2 lcd, 32,["Dist- "]
    SerOut2 lcd, 32,[254,"G",11,4] 'set home on 4th line
    SerOut2 lcd, 32,["Sat- "]



    'main program
    '-------------------------------------------------------------

    start:
    SerIn2 gps, 24764, [WAIT("$GPRMC"),b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b 11]

    SerOut2 lcd, 32,[254,"G",2,2]
    SerOut2 lcd, 32,[#b3," "]

    SerOut2 lcd, 32,[254,"G",12,2]
    SerOut2 lcd, 32,[#b5," "]

    SerOut2 lcd, 32,[254,"G",8,3]
    SerOut2 lcd, 32,[#b7," "]


    Pause 2000


    GoTo start
    End


    thanks

  2. #2
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    have you tried receiving the entire string first, and then parsing the received string?


    SerIn2 gps, 24764, [WAIT("$GPRMC"),str GPRMC_IN\65]

  3. #3
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    i have sort of been learing this stuff just by examples and playing around until i can get it to work... im not exaclty sure how to do that... i understand saving the whole string as one variable, but how do i access the data after it is saved??

    thanks

  4. #4
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    well, unfortunately you can't just explicitly say position 42, 43 are speed because the strings are variable length (ex: speed = 0.0, speed = 94.2)

    so i setup loops to record each data (i'm sure there's probably a more efficient way to do it)

    ex:
    i = absolute position number in the ascii string
    j = local counter

    'BEGIN PROCESSING
    i = 0 'i is the position holder in the ascii string received
    'get HOUR in convertible decimal format, then convert it with subroutine
    H[0] = gprmc_in[0]-48
    H[1] = gprmc_in[1]-48
    hour = H[0]*10 + H[1]
    gosub convert_time

    i = 2
    FOR J = 0 TO 1
    MINUTE[J] = GPRMC_IN[I] - 48
    I = I + 1
    NEXT J

    FOR J = 0 TO 1
    SEC[J] = GPRMC_IN[I] - 48
    I = I + 1
    NEXT J

    i = i + 5

    STAT = gprmc_in[i] 'Write GPS Status Indicator
    i = i + 1


    'Check for valid Data
    if STAT != "A" then
    goto gprmc_bad_data
    endif

    i = i + 1
    HIGH LED

    for j = 0 to 1 'get Lattitude Degree[2]
    rmc_latD[j] = gprmc_in[i]
    i = i + 1
    next j

  5. #5
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    ok, thanks for the help... it appears that im gonna need to learn a lot more before i can get this to work... i dont understand most of the stuff you just said so im gonna have to learn all that stuff....

    thanks

  6. #6
    leinske's Avatar
    leinske Guest


    Did you find this post helpful? Yes | No

    Smile Working code for GPS

    I Dragon Fire if it can help you, here is the complete code file for a similar application I made for my GPS repeater for my sailboat :


    ' Program to display returned value of a GPS on RB1
    ' LCD in 4-BIT mode PIC16F628 controller 4Mhz clock Fuse PWRT BODEN
    'This version include: engine rpm,heading and speed,heading and range to WP
    '
    ' LCD should be connected as follows:
    ' LCD PIC
    ' DB4 PortA.0
    ' DB5 PortA.1
    ' DB6 PortA.2
    ' DB7 PortA.3
    ' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
    ' E PortB.3
    ' RW Ground
    ' Vdd 5 volts
    ' Vss Ground
    ' Vo 20K potentiometer (or ground)
    ' DB0-3 No connect
    'GPS sentence: $GPRMC,192144.62,A,5041.6058,N,00412.6124,E,0.45,3 57.74,081205,,*0B
    'Route sentence: $ECBWC,000000,5110.063,N,00236.403,E,276.4,T,277.6 ,M,3.15,N,02-NIEUWPOORT-BANK*34
    @ DEVICE PIC16F628A,XT_OSC,WDT_OFF,PWRT_ON,MCLR_OFF,BOD_ON, LVP_OFF,PROTECT_OFF

    DEFINE OSC 4
    CMCON = 7

    GPSin VAR PORTB.1
    RPMin VAR PORTB.4 'input from rpm module optical with 2 marks on flyweel
    TRISB.1=1 'define port B1 as input
    TRISB.5=1 'define port B5 as input
    TRISB.4=1 'define port B4 as input
    TRISA.0=0 'define PORT A output for LCD DB4
    TRISA.1=0 'define PORT A output for LCD DB5
    TRISA.2=0 'define PORT A output for LCD DB6
    TRISA.3=0 'define PORT A output for LCD DB7
    TRISA.4=0 'define PORT A output for LCD RS
    TRISB.3=0 'define PORT B output for LCD E


    PORTA=0
    PORTB=0

    'Allocate Variables for GPS:
    TimeOut CON 3000
    baudGPS CON 24764 '16572 + 8192 (bit 13)
    RPM VAR WORD 'motor revolutions

    truecourse VAR WORD 'true course to WP
    magcourse VAR WORD 'magnetic course to WP
    dist VAR BYTE 'distance to WP units
    distten VAR BYTE 'distance to WP tens
    wpid VAR BYTE 'WP id nb
    wp VAR BYTE[16] 'WP name



    hh VAR BYTE 'hours
    mm VAR BYTE 'minutes
    j VAR BYTE 'day
    m VAR BYTE 'month
    a VAR BYTE 'year
    knots VAR WORD 'speed in knots (units)
    knotsten VAR BYTE 'speed in knots (tens)
    course VAR WORD 'heading
    latdeg VAR BYTE 'degrees latitude
    latmin VAR BYTE 'minutes latitude
    NS VAR BYTE 'north or south
    londeg VAR BYTE 'degrees longitude
    lonmin VAR BYTE 'minutes longitude
    EO VAR BYTE 'east or west


    fix VAR WORD 'GPS fix

    'initialize variables
    hh=0
    mm=0
    j=0
    m=0
    a=0
    knots="0"
    knotsten=0
    course=0
    latdeg=0
    latmin=0
    NS="N"
    londeg=0
    lonmin=0
    EO="S"
    truecourse=0
    magcourse=0
    dist="0"
    distten=0
    wpid=0

    LCDOut $FE, 1 'Clear Screen
    LCDOut " POP CORN"
    LCDOut $fe,$c0
    LCDOut " WELCOME ABOARD"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " YOUR SKIPPER"
    LCDOut $fe,$c0
    LCDOut " ALAIN DE VOS"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen



    GPS: 'read GPS

    'read motor revolutions
    Count RPMin,600,RPM
    IF RPM<2Then
    GoTo readgps
    Else
    RPM=RPM*50
    LCDOut $FE, 1 'Clear Screen
    LCDOut "ENGINE SPEED:"
    LCDOut $fe,$c0
    LCDOut #RPM," RPM"
    Pause 2000
    EndIF



    readgps:
    SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPRMC"),wait(","),DEC2 hh,DEC2 mm,wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait(","),EO,wait(","),knots,wait("."),DEC2 knotsten,wait(","),DEC3 course,wait(","),DEC2 j,DEC2 m,DEC2 a]



    IF fix="V" Then 'if no GPS fix
    GoTo Nofix
    EndIF


    LCD:


    'normal display if fix ok
    LCDOut $FE, 1 'Clear Screen
    LCDOut "SPEED :",knots,",",DEC2 knotsten,"KNT"
    LCDOut $fe,$c0
    LCDOut "HEADING:",DEC3 course,223,"TRUE"
    Pause 3000


    LCDOut $FE, 1 'Clear Screen
    LCDOut DEC2 j,"-",DEC2 m,"-",DEC2 a," ",DEC2 hh,":",DEC2 mm
    LCDOut $fe,$c0
    LCDOut DEC2 latdeg,223,DEC2 latmin,39,NS," ",DEC2 londeg,223,DEC2 lonmin,39,EO
    Pause 3000

    'Get route informations from serial port
    SerIn2 GPSin,baudGPS,Timeout,norte,[wait("$ECBWC"),wait(","),wait(","),DEC2 latdeg,DEC2 latmin,wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait(","),EO,wait(","),DEC3 truecourse,wait(","),wait(","),DEC3 magcourse,wait(","),wait(","),DEC2 dist,wait("."),DEC2 distten,wait(","),wait(","),DEC2 wpid,wait("-"),STR wp\16\"*"]


    'display route informations
    LCDOut $FE, 1 'Clear Screen
    LCDOut "WAYPOINT WP",DEC2 wpid,":"
    LCDOut $fe,$c0
    LCDOut STR wp
    Pause 3000

    LCDOut $FE, 1 'Clear Screen
    LCDOut "POSITION WP",DEC2 wpid
    LCDOut $fe,$c0
    LCDOut DEC2 latdeg,223,DEC2 latmin,39,NS," ",DEC2 londeg,223,DEC2 lonmin,39,EO
    Pause 3000

    LCDOut $FE, 1 'Clear Screen
    LCDOut "HEADING TO WP",DEC2 wpid
    LCDOut $fe,$c0
    LCDOut DEC3 truecourse,223,"TRUE",61,DEC3 magcourse,223,"MAG"
    Pause 3000

    LCDOut $FE, 1 'Clear Screen
    LCDOut "DISTANCE TO WP",DEC2 wpid
    LCDOut $fe,$c0
    LCDOut DEC2 dist,",",DEC2 distten," NM"
    Pause 2000


    GoTo GPS


    'display if no gps is present
    Nogps:
    Pause 1000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " NO GPS"
    LCDOut $fe,$c0
    LCDOut " CHECK CABLES "
    Pause 1000
    GoTo GPS

    'display if no gps fix
    Nofix:

    'display last valid from GPS
    Pause 1000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " NO GPS FIX"
    LCDOut $fe,$c0
    LCDOut " LAST VALID"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen
    LCDOut "LAT:",DEC2 latdeg,223,DEC2 latmin,39,NS
    LCDOut $fe,$c0
    LCDOut "LON:",DEC2 londeg,223,DEC2 lonmin,39,EO
    Pause 2000
    GoTo GPS

    norte:
    'display if no active route
    Pause 1000
    LCDOut $FE, 1 'Clear Screen
    LCDOut "NO ACTIVE ROUTE"
    Pause 1000
    GoTo GPS

  7. #7
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    thanks for the reply.. i understand that a lot more than i did before... my lcd is currently not working, and i dont know why, so as soon as i get it fixed, or i get another, i will retry writing the code using your example...

    thanks

    danny

  8. #8
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    OK, i think ive got the basics of how to do this... im sorry if it seems like im asking you all to write the code for me, but im not... im just one of those people that figure the best way to learn is from examples.. i have tried changing leinske's code to make it display with a serial lcd, and what data it displays... i got it to work, except for displaying the course... thanks for that, i learnt a lot from it.... i just learned that my gps does output GPAPB sentences (only outputs it if there is a route active), and so i changed the code for it... i just want to display waypoint name and distance and direction for some geocaching stuff i am working on... when i try to compile, it says that there is an error. it says "expected ]"... i know its probably a stupid mistake somewhere, but i cant find it.... im using a 16f88 at 10mhz, with an epic programmer... the gps is a sporttrak map.... thanks for all the help...


    @ DEVICE HS_OSC
    DEFINE OSC 10
    cmcon = 7
    TRISA = %00000000

    'variables
    '-------------------------------------------------------------
    lcd VAR PORTA.3
    gpsin VAR PORTB.0
    GPAPB_IN VAR BYTE
    TimeOut CON 3000
    baudGPS CON 24764 '16572 + 8192 (bit 13)
    blink VAR BYTE 'SNR warning
    warning VAR BYTE 'cycle warning
    xtrack VAR WORD 'crosstrack error
    lrcorrect VAR WORD 'steer right or left to correct
    xtrackunits VAR BYTE 'cross track error units n or k
    arrivalcircle VAR WORD 'arrival alarm circular
    arrivalperp VAR WORD ' arrival alarm perpendicular
    magbear VAR WORD 'origin to dest 'magnetic bearing
    dest VAR WORD 'destination ID
    bear VAR WORD 'position to dest
    head VAR WORD 'heading to steer

    'initialize variables

    'setup serial lcd
    '-------------------------------------------------------------

    Pause 5000
    SerOut2 lcd, 32,[254,"X"] 'clear screen
    Pause 100

    'main program
    '-------------------------------------------------------------

    GPS: 'read GPS

    SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPAPB"), wait(","), blink, wait(","), warning, wait(","), DEC2 xtrack, wait(","), lrcorrect, wait(","), xtrackunits, wait(","), arrivalcirlce, wait(","), arrivalperp, wait(","), DEC3 magbear, wait(",$,"), mag, wait(","), dest, wait(","), DEC3 bear, wait(","), DEC3 head]

    SerOut2 lcd, 32,[254,"G",4,1]
    SerOut2 lcd, 32,[#lrcorrect," "]
    SerOut2 lcd, 32,[254,"G",1,2]
    SerOut2 lcd, 32,[#magbearing," "]
    SerOut2 lcd, 32,[254,"G",4,2]
    SerOut2 lcd, 32,[#mag," "]
    SerOut2 lcd, 32,[254,"G",1,3]
    SerOut2 lcd, 32,[#dest," "]
    SerOut2 lcd, 32,[254,"G",4,3]
    SerOut2 lcd, 32,[#magbear," "]
    SerOut2 lcd, 32,[254,"G",1,1]
    SerOut2 lcd, 32,[#maghead," "]

    Pause 500
    GoTo gps

    Nogps:
    Pause 100
    SerOut2 lcd, 32,[254,"X"]
    SerOut2 lcd, 32,[254,"G",5,2]
    SerOut2 lcd, 32,[" NO GPS"]
    Pause 100
    GoTo GPS

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Replies: 1
    Last Post: - 27th July 2008, 06:14
  3. GPS clock timing !
    By bethr in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 3rd July 2008, 20:11
  4. Replies: 2
    Last Post: - 28th April 2006, 12:10
  5. GPS Receiver
    By lester in forum Adverts
    Replies: 2
    Last Post: - 22nd February 2006, 12:47

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts