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

GSM Shield SIM900D with PIC16F877A

Hi there!..So this is my partial project for my research proposal on how I integrated my GSM Shield module, specifically the SIM900D, with the PIC16F877A microcontroller unit. In this project, I only constructed a sending process function by using a push-button. Therefore, every time I would press the push-button, a fixed message would be sent to a specific recipient. This is only a basic construction of understanding the GSM Shield function and its AT Commands.

The image that is shown below is the GSM Shield SIM900D that I used for my project. You can purchase this at http://www.e-gizmo.com/KIT/gsm%20shield.html for about 1,995.00 pesos.



Features and Specifications of GSM/GPRS Shield:
 • Industry proven SIMCOM SIM900D Module 
• Buffered UART provides additional layer of protection
• Fused power input
• On board LDO voltage regulator
• UART/SUART switch selectable port (gizDuino)
• On board manual power switch
• SIM Card Holder


Here is the circuit I made by integrating the PIC16F877A and the GSM Shield:




Be sure to connect the Tx of the GSM Shield to the Tx of the PIC and the Rx of the GSM Shield to the Rx of the PIC. Take note also that the GSM needs to be powered by a 1.5A and 5VDC supply and its ground must be COMMON to the ground of the circuit.

For the PIC16F877A programming code, I used a programming language which is the "MikroC Pro for PIC". MikroC has an awesome and numerous features of built-in libraries along with examples of small programs in order for the user to simply understand the functions. Here is my program code: (REMEMBER: This is only a sending process, it does not consist of a receiving capability yet.)



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

void GSM_Init(void);

void GSM_send(void);
void GSM_receive(void);

void main(void) {


TRISD=0b00000010;     //RD1 is an input

PORTD=0x00;                //The rest of RD pins are output

UART1_Init(9600);     //Initialize and establish communication at 9600 bps

Delay_ms(250);
UART1_Write_Text("AT+CMGD=1");  //Delete mesage sotred in inbox1
UART1_Write(0x0D);              //<CR>

while(1)

{

if(PORTD.F1==0)           //if pushbutton is pressed

{
  PORTD.F0=0;               //LED OFF

  GSM_Init();                   //calls GSM_Init function

  GSM_send();                 //calls GSM_send function

  PORTD.F0=1;                //LED1 blinks 3 times

  Delay_ms(250);

  PORTD.F0=0;

  Delay_ms(250);

  PORTD.F0=1;

  Delay_ms(250);

  PORTD.F0=0;
  Delay_ms(250);

  PORTD.F0=1;

  Delay_ms(250);

  PORTD.F0=0;

  Delay_ms(250);
  }


 }

}
/*----------------------------------------------------------------------
                      GSM INITIALIZING PROCESS
----------------------------------------------------------------------*/

void GSM_Init(void)

{
  UART1_Write_Text("AT\r");
  UART1_Write_Text("AT+CMGF=1");      //Text Mode
  UART1_Write(0x0D);                                //<CR>
  Delay_ms(250);
  UART1_Write_Text("AT+CMEE=2");      //Write Mode
  UART1_Write(0x0D);                               //<CR>
  Delay_ms(250);
  UART1_Write_Text("AT+CFUN=1");      //Full Phone Functionality
  UART1_Write(0x0D);                               //<CR>
  Delay_ms(250);
}

/*----------------------------------------------------------------------

                       GSM SENDING PROCESS
----------------------------------------------------------------------*/

void GSM_send(void)

{
  UART1_Write_Text("AT+CMGS=\"09429185691\"");    //send SMS to this number
  UART1_Write(0x0D);                              //<CR>
  Delay_ms(250);
  UART1_Write_Text("F.M.S. GSM with PIC Testing\r");  //message to be sent
  UART1_Write(0x1A);                                  //<CTRL+Z>
  Delay_ms(250);

}


Here is an actual video of what I have made:





Project made by: Kirk Benedict P. Macaraeg