Thursday 5 December 2013

GPS Shield with PIC16F877A

Hello there! Here is another integration test for my research proposal (Fleet Management System) that composes of a GPS Shield. In this project, I have integrated the GPS Shield with the PIC16F877A and a 2x16 LCD. The information from the GPS Satellite, specifically the latitude and the longitude, would be captured and will be displayed on the 2X16 LCD.

The image shown below is the GPS Shield module that I used for my project. You may be able to purchase this module at http://www.e-gizmo.com/KIT/gps%20shield.html for 1,385 pesos.


An image below that is shown is the circuit diagram for the connection of the devices which are the GPS Shield, the MCU PIC16F877A and lastly the 2x16 LCD.



As I said earlier, I used a "2x16" LCD and the image shown here is a"2x14" LCD. This is because i used proteus for circuit design and simulation and the 15 and 16 are neglected due to the built in function of the device. In actual, the pin 15 is the anode and the 16 is the cathode. The purpose of pin 15 and 16 is that it turns on the LED/light background of the LCD. To attain this, simply connect pin 15 of the LCD to the 5VDC source and the pin 16 to the GND.

As for the TX and RX connection, only connect the Rx of the GPS to the Rx of the PIC16F877A, We will neglect the TX since we would only retrieve the information of the latitude and longitude. 

Here is the program code I have made for this project:
NOTE: The programming software i used is the MikroC PIC Pro. In order for this to work, you need to download the MikroC PIC Pro and download the NMEA library function in order for you to be able to utilize some functions used for the GPS Shield. The NMEA library can be downloaded here : http://www.libstock.com/projects/view/695/nmea-library


/*---------------------------FLEET MANAGEMENT SYSTEM-------------------------
         MikroC Programming by Kirk
----------------------------------------------------------------------------*/

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections



char txt5[] = "GPS with PIC877A";
char txt6[] = "F.M.S.";





// Variables
int i = 0;
int received = 0;
char DataType[] = "GPXXX";
char NMEA[] = "$xxxxx,xxxxxxxxx,xxxx.xxx,x,xxxxx.xxx,x,x,xx,x.x,xxx.x,x,xx.x,x,,*xx";
char receive;
// End Variables

void main(){

  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,txt5);                 // Write text in first row
  Lcd_Out(2,6,txt6);                 //displays txt5
  Delay_ms(5000);                    //displays txt6
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Delay_ms(250);


  UART1_Init(9600);         // Initialize UART for GPS board connectivity
 //LCD Stuff
 LCD_Out(1,1, "Lat:                 ");
 LCD_Out(2,1, "Lon:                 ");

 LCD_Chr(1, 7, 0x20);  //Degree Character
 //LCD_Chr(2, 8, 0xB0);  //Degree Character
 LCD_Chr(2, 8, 0x20);  //' Character
 LCD_Chr(2, 11, 0x2E);  //' Character

 //End of LCD

  while(1) {
  if (UART1_Data_Ready() == 1) {
   receive = UART1_Read();
   if (receive == '$')  // Check if sentence begins.
   {
        received = 0;
        do{
          if (UART1_Data_Ready() == 1)
          {
           UART1_Read_Text(DataType, ",", 10);  // Capture GPXXX word
           received = 1;
          }
        } while(received == 0);
        // If it is GPGGA Data, then acquire it.
        if ((DataType[2] == 'G') && (DataType[3] == 'G') && (DataType[4] == 'A'))
        {
          received = 0;
          do{
            if (UART1_Data_Ready() == 1)
            {
             UART1_Read_Text(NMEA, "*", 100);   // Stop at *XX checksum data
             received = 1;
            }
          } while(received == 0);
          // Fill LCD with relevant data     */
          // Latitude
          LCD_Chr(1, 5, NMEA[11]);
          LCD_Chr(1, 6, NMEA[12]);

          LCD_Chr(1, 8, NMEA[13]);
          LCD_Chr(1, 9, NMEA[14]);

          LCD_Chr(1, 10, NMEA[15]);
          LCD_Chr(1, 11, NMEA[16]);
          LCD_Chr(1, 12, NMEA[17]);
          LCD_Chr(1, 13, NMEA[18]);
          LCD_Chr(1, 14, NMEA[19]);
          //LCD_Chr(1, 15, NMEA[20]);
          LCD_Chr(1, 16, NMEA[21]);

          // Longitude
          LCD_Chr(2, 5, NMEA[23]);
          LCD_Chr(2, 6, NMEA[24]);
          LCD_Chr(2, 7, NMEA[25]);

          LCD_Chr(2, 9, NMEA[26]);
          LCD_Chr(2, 10, NMEA[27]);

          LCD_Chr(2, 12, NMEA[29]);
          LCD_Chr(2, 13, NMEA[30]);
          LCD_Chr(2, 14, NMEA[31]);
          LCD_Chr(2, 15, NMEA[32]);
          LCD_Chr(2, 16, NMEA[34]);

          //LCD_Chr(2, 15, NMEA[35]);
          }
           receive = "x";
   }
   }
   }
   }

Here are some images of this project and its actual video footage:








Project made by: Kirk Benedict P. Macaraeg

17 comments:

  1. how can i add the nmea library to the program and to what pin if the PIC16F877A to connect the input. is it at Pin 20

    ReplyDelete
  2. can you post instead the HEX program complete with the nmea library. tnx and more power. i realy like your project coz i have the same gps shield

    ReplyDelete
  3. Hii i have been working on this project and simulation is done but the co-ordinates showing are LAT:,M,0.0,M,0 and LNG:00 X,.XXXXX...so can u please help me in getting the actual co-ordinates

    ReplyDelete
    Replies
    1. If simulation is done can you correct the above program its not working ?

      Delete
  4. how to connect GPS device and 16F877A

    ReplyDelete
  5. where do i place the NMEA library that i downloaded.? please reply..thanks. :)

    ReplyDelete
  6. i downloaded the NMEA library and install it..but __Lib_NMEA.c not found..please help..

    ReplyDelete
  7. how to connect GPS device and 16F877A by mikrobasic source

    ReplyDelete
  8. how to connect GPS device and 16F877A by mikrobasic source

    ReplyDelete
  9. how to connect GPS device and 16F877A by mikrobasic source

    ReplyDelete
  10. how to connect GPS device and 16F877A by mikrobasic source

    ReplyDelete
  11. i downloaded the NMEA library and install it..but __Lib_NMEA.c not found..please help..

    ReplyDelete
  12. THIS CODE IS WORKING PERFECTLY WITHOUT THE LIBRARY BUT NEEDS SOME PHRASING ENHANCEMENTS

    ReplyDelete
  13. you have done a great job but there is a small issue with pic 16 family(__Lib_NMEA.c not found) and no errors when select pic18 family. Need to setup with pic16f877a. If possible let me know any solution available to overcome.
    Thanks

    ReplyDelete
  14. use package manager to add nmea library

    ReplyDelete