EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Interface GPS with PIC18F4550 Microcontroller

Interface GPS with PIC18F4550 Microcontroller

|

Microcontroller › PIC › Interface GPS with PIC18F4550 Microcontroller

  • This topic has 1 reply, 2 voices, and was last updated 10 years, 5 months ago by Prabakaran P M.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • August 31, 2015 at 2:04 am #3944
    KOH YUEN KHANG
    Participant

    // Program to Interface GPS with PIC18F4550 Microcontroller

    #include <xc.h>
    #include <p18f4550.h>
     

    #define FREQ 12000000 #define baud 4800 #define spbrg_value (((FREQ/64)/baud)-1) #define rs LATA.F0 #define rw LATA.F1 #define en LATA.F2 #define lcdport LATB

    unsigned char rx_data();
    void lcd_ini();
    void lcdcmd(unsigned char);
    void lcddata(unsigned char);

    unsigned char longi_data[12];
    unsigned char lati_data[12];
    unsigned char data,value=0;
    unsigned int i=0,pos;

    void main()
    {
    TRISB=0; // Set Port B as output port
    LATB=0;
    TRISA=0;
    LATA=0;
    SPBRG=spbrg_value; // Fill SPBRG register to set the baud rate
    RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins)
    RCSTA.CREN=1; // To enable continuous reception
    lcd_ini();
    while(1)
    {
    data=rx_data(); // Check the string '$GPGGA,'
    if(data=='$')
    {
    data=rx_data();
    if(data=='G')
    {
    data=rx_data();
    if(data=='P');
    {
    data=rx_data();
    if(data=='G');
    {
    data=rx_data();
    if(data=='G')
    {
    data=rx_data();
    if(data=='A')
    {
    data=rx_data();
    if(data==',')
    {
    data=rx_data();
    while(data!=',')
    data=rx_data();
    for(i=0;data!='N';i++)
    data=rx_data();
    lati_data=data; // Store the Latitude data
    }
    data=rx_data();
    if(data==',')
    {
    for(i=0;data!='E';i++)
    {
    data=rx_data();
    longi_data
    =data; // Store the Longitude data
    }
    }
    i=0;
    lcdcmd(0x80);
    while(i<11)
    {
    lcddata(lati_data
    ); // Print the Latitude data
    i++;
    }
    i=0;
    lcdcmd(0xC0);
    while(i<12)
    {
    lcddata(longi_data
    ); // Print the Longitude data
    i++;
    }
    }
    }
    }
    }
    }
    }
    }
    Delay_ms(1000);
    for(i=0;i<12;i++)
    {
    data=0;
    lati_data
    =0;
    longi_data
    =0;
    }
    }
    }

    unsigned char rx_data(void)
    {
    while(PIR1.RCIF==0); // Wait until RCIF gets low
    return RCREG; // Store data in Reception register
    }

    void lcd_ini()
    {
    lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5×7 font
    lcdcmd(0x0C); // Display On and Cursor Off
    lcdcmd(0x01); // Clear display screen
    lcdcmd(0x06); // Increment cursor
    lcdcmd(0x80); // Set cursor position to 1st line, 1st column
    }

    void lcdcmd(unsigned char cmdout)
    {
    lcdport=cmdout; //Send command to lcdport=PORTB
    rs=0;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
    }

    void lcddata(unsigned char dataout)
    {
    lcdport=dataout; //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
    }

     

    I obtanied the code above from the link below:

    http://www.engineersgarage.com/embedded/pic-microcontroller-projects/gps-interface-circuit

    I'm using MPlab IDE with xc8 compiler to run this code but I encountered the error below:

    Executing: "C:Program FilesMicrochipxc8v1.35binxc8.exe" –pass1 "C:UsersHui YiDesktoppic18f4550test.c" -q –chip=18F4550 -P –runtime=default –opt=default -N-1 -D__DEBUG=1 -g –asmlist "–errformat=Error   [%n] %f; %l.%c %s" "–msgformat=Advisory[%n] %s" "–warnformat=Warning [%n] %f; %l.%c %s" 
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 29.11 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 30.11 struct/union required
    Warning [361] C:UsersHui YiDesktoppic18f4550test.c; 92.1 function declared implicit int
    Error   [285] C:UsersHui YiDesktoppic18f4550test.c; 100.1 no identifier in declaration
    Warning [374] C:UsersHui YiDesktoppic18f4550test.c; 100.1 missing basic type; int assumed
    Error   [314] C:UsersHui YiDesktoppic18f4550test.c; 100.1 ";" expected
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 104.16 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 120.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 121.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 122.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 124.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 130.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 131.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 132.8 struct/union required
    Error   [196] C:UsersHui YiDesktoppic18f4550test.c; 134.8 struct/union required
    (908) exit status = 1
     
    Can anyone tell me whats wrong with this code or any things i have to add with?
     
    August 31, 2015 at 4:11 am #13233
    Prabakaran P M
    Participant

    Hi KOH YUEN KHANG,

    Copy the code from the page exactly as it is and make it look like same in the page use HitechC compiler.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Harman Kardon radio module BMW noise February 16, 2026
  • Arduino standalone minimal February 16, 2026
  • analog logic of shmidt trigger bjt circuit February 16, 2026
  • CR2/CR123A Batteries In Projects February 16, 2026
  • Math problem February 15, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise