PIC16F877A with GPS and GSM for tracking purpose

Home Forums Microcontrollers PIC Microcontroller PIC16F877A with GPS and GSM for tracking purpose

Tagged: , ,

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #10935
    vineethkumarc
    Participant

    Hi,

    Can we connect both GPS and GSM to a Single PIC having one UART?

    How its implemented and how the circuits operates?

    Kindly Help…

    #10936
    Ligo George
    Keymaster

    Yes, you can. You have two options.

    1. Multiplex UART using IC 74HC4052
    2. Using Software UART, which means that you can program any GPIO pin of PIC as UART. MikroC Pro provides built in library for that.
    #10937
    vineethkumarc
    Participant

    Thank you so much…

    can you provide me the code?

    #10942
    Ligo George
    Keymaster

    If you are using MikroC, please use the HELP section to find details of SoftUART library. It is very easy to use.

    #10945
    vineethkumarc
    Participant

    thank you…’

     

    #10949
    vineethkumarc
    Participant

    Sir,

    I need to display latitude and longitude recieved from GPS in LCD…

    Is the following code is enough?
    Pls help me…

     

    #10962
    vineethkumarc
    Participant

    iitilise portE,8,9,9600,0 as the uart..

    but cant proceed..

    kindly help

    #10977
    Ligo George
    Keymaster

    Firstly store all characters to a character array.. then print that string on LCD.

    #11011
    vineethkumarc
    Participant

    hi,
    this is the code written to dispaly and snd msg to gsm with the gps data..
    I use software uart for recieving gps data..is there any problem?

    sbit LCD_RS at RB2_bit;
    sbit LCD_EN at RB3_bit;
    sbit LCD_D7 at RB7_bit;
    sbit LCD_D6 at RB6_bit;
    sbit LCD_D5 at RB5_bit;
    sbit LCD_D4 at RB4_bit;
    // Pin direction
    sbit LCD_RS_Direction at TRISB2_bit;\
    sbit LCD_EN_Direction at TRISB3_bit;
    sbit LCD_D7_Direction at TRISB7_bit;
    sbit LCD_D6_Direction at TRISB6_bit;
    sbit LCD_D5_Direction at TRISB5_bit;
    sbit LCD_D4_Direction at TRISB4_bit;
    // END LCD
    
    // GPS
    char Gpsdata,gps,error;               // for incoming serial data
    unsigned int finish =0;    // indicate end of message
    unsigned int pos_cnt=0;    // position counter
    unsigned int lat_cnt=0;    // latitude data counter
    unsigned int log_cnt=0;    // longitude data counter
    unsigned int time_cnt=0;
    unsigned int flg=0;       // GPS flag
    unsigned int com_cnt=0;   // comma counter
    
    char time[20];
    char lat[20],lat1[20],lat2[20];             // latitude array
    char lg[20],lg1[20],lg2[20];              // longitude array
    
    //GSM
    void Receive_GPS_Data();
    void GSM_Initialisation();
    void GSM_Write();
    void GSM_Read();
    void main()
    {
      Soft_Uart_init(&PORTD,1,2,9600,0);
    
      do
      {
        int t;
        finish = 0;pos_cnt = 0;
        Receive_GPS_Data();
        Lcd_Init();         // Initialize LCD connected to PORTB
        Lcd_Cmd(_LCD_CLEAR);       // Clear display 
        Lcd_Cmd(_LCD_CURSOR_OFF);  // Turn cursor off
        Lcd_Out(1, 1,"log");      // Print text to LCD, 1st row, 1st column
        Lcd_Chr_Cp(lg);
        Lcd_Out(2, 1,"lat");     //  Print text to LCD, 2nd row, 1st column
        Lcd_Chr_Cp(lat);
    
        for(t=10;t>=0;t--)
        {
          Delay_ms(200);
          if((lat1==lat)&&(lg1==lg))
          {
            lat2[20]=lat1[20];
            lg2[20]=lg1[20];
          }
          if((lat2!=lat1)&&(lg2!=lg1))
          {
            GSM_Initialisation();
            GSM_Write();
          }
        }
    
        while(UART1_Data_Ready()==1)
        {
          GSM_Initialisation();
          GSM_Read();
          GSM_Write();
        }
      }
      while(1);
    }
    
    void Receive_GPS_Data()
    {
      do
        Gpsdata = Soft_UART_Read(&error);
      while (error);
    
      while(finish==0)
      {
        Gpsdata = Soft_Uart_Read(&error);
        flg = 1;
        if( Gpsdata=='$' && pos_cnt == 0)   // finding GPRMC header
        pos_cnt=1;
        if( Gpsdata=='G' && pos_cnt == 1)
        pos_cnt=2;
        if( Gpsdata=='P' && pos_cnt == 2)
        pos_cnt=3;
        if( Gpsdata=='R' && pos_cnt == 3)
        pos_cnt=4;
        if( Gpsdata=='M' && pos_cnt == 4)
        pos_cnt=5;
        if( Gpsdata=='C' && pos_cnt==5 )
        pos_cnt=6;
        if(pos_cnt==6 &&  Gpsdata ==',')
        {
          // count commas in message
          com_cnt++;
          flg=0;
        }
        if(com_cnt==3 && flg==1)
        {
          lat[lat_cnt++] =  Gpsdata;         // latitude
          flg=0;
        }
        if(com_cnt==5 && flg==1)
        {
          lg[log_cnt++] =  Gpsdata;         // Longitude
          flg=0;
        }
        lat1[20]=lat[20];
        lg1[20] = lg[20];
        if( Gpsdata == '*' && com_cnt >= 5)
        {
          com_cnt = 0;                      // end of GPRMC message
          lat_cnt = 0;
          log_cnt = 0;
          flg     = 0;
          finish  = 1;
        }
      }
    }
    
    void GSM_Initialisation()
    {
      UART1_Init(9600);
      Delay_ms(1000);
      UART1_Write_Text("AT");
      UART1_Write(10);
      UART1_Write(13);
      delay_ms(500);
      UART1_Write_Text("ATE0");
      UART1_Write(10);
      UART1_Write(13);
      delay_ms(500);
      UART1_Write_Text("AT+CMGF=1");
      UART1_Write(10);
      UART1_Write(13);
      delay_ms(500);
    }
    
    void GSM_Write()
    {
      UART1_Write_Text("AT+CMGS=\"+919946977684\"");
      UART1_Write(10);
      UART1_Write(13);
      delay_ms(500);
      UART1_Write_Text("THEFT ALERT");
      UART1_Write(lat);
      UART1_Write(lg);
      UART1_Write(0x1A);
      Delay_ms(1000);
      UART1_Write_Text("ATD=9946977684");
      UART1_Write(10);
      UART1_Write(13);
      delay_ms(500);
    }
    
    void GSM_Read()
    {
      int i,w=0;
      char msg[55];
      UART1_Write_Text("AT+CMGL=\"REC UNREAD\"\r");
      UART1_Write(10);
      UART1_Write(13);
      Delay_ms(5000); 
      UART1_Write_Text("AT+CMGR=1\r");
      for(i=0;i<75;i++)
      {
        if(UART1_Data_Ready())
        {
           msg[w] = UART1_Read();
           ++w;
        }
      }
     msg[55] = '';
    }
    #11021
    thiruppathi
    Participant

    Hi, you can do with one UART  ,  bcoz GPS only act as a receiver, use the second RX and TX in max 232 ic pins,In program  don’t forget the disable the serial interrupt at the time of message sending.

    #11027
    Ligo George
    Keymaster

    You should use UART1_Read_Text() or UART1_Read() without any delays
    Eg:

    for(i=0;i<34;)
    {
       if(UART1_Data_Ready())
       {
           s[i] = UART1_Read();
           i++;
       }
    }
    // All further data processing or LCD commands should be here.. 
    
    #11029
    vineethkumarc
    Participant

    hi

    but while compiling i got an error..

    pointer require..

    when initialise gpsdata as an array,the entire processing part has to change…

    so pls pls help me

     

    #11035
    Ligo George
    Keymaster

    That error will be related to standard C syntax and usage.

    #11038
    vineethkumarc
    Participant

    thanks..
    I got the latitude and longitude from gps and displayed it on lcd but while sending through GSM,it is not possible.

    #11044
    Ligo George
    Keymaster

    Try using following functions.

    void gsmInit()
    {
      UART1_Init(9600);
      Delay_ms(200);
      UART1_Write_Text("ATE0\r"); // ECHO OFF
      Delay_ms(100);
      UART1_Write_Text("AT+CMGF=1\r"); // Text Mode
      Delay_ms(100);
      UART1_Write_Text("AT+CNMI=2,0,0,0,0\r");
      Delay_ms(100);
    }
    
    void gsmSendSMS(char mobile[11], char message[10])
    {
      UART1_Write_Text("AT+CMGS=\"");
      UART1_Write_Text(mobile);
      UART1_Write_Text("\"\r");
      UART1_Write_Text(message);
      UART1_Write_Text(26);
      Delay_ms(100);
    }
    
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.
>