Home › Forums › Microcontrollers › PIC Microcontroller › PIC16F877A with GPS and GSM for tracking purpose
Tagged: GPS, GSM, pic16f877a
- This topic has 16 replies, 4 voices, and was last updated 7 years, 2 months ago by Roshan Acharya.
-
AuthorPosts
-
February 27, 2015 at 9:33 pm #10935vineethkumarcParticipant
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…
February 27, 2015 at 9:49 pm #10936Ligo GeorgeKeymasterYes, you can. You have two options.
- Multiplex UART using IC 74HC4052
- Using Software UART, which means that you can program any GPIO pin of PIC as UART. MikroC Pro provides built in library for that.
February 28, 2015 at 11:25 am #10937vineethkumarcParticipantThank you so much…
can you provide me the code?
March 1, 2015 at 10:09 am #10942Ligo GeorgeKeymasterIf you are using MikroC, please use the HELP section to find details of SoftUART library. It is very easy to use.
March 1, 2015 at 11:26 am #10945vineethkumarcParticipantthank you…’
March 1, 2015 at 1:24 pm #10949vineethkumarcParticipantSir,
I need to display latitude and longitude recieved from GPS in LCD…
Is the following code is enough?
Pls help me…March 2, 2015 at 10:18 pm #10962vineethkumarcParticipantiitilise portE,8,9,9600,0 as the uart..
but cant proceed..
kindly help
March 3, 2015 at 8:01 pm #10977Ligo GeorgeKeymasterFirstly store all characters to a character array.. then print that string on LCD.
March 9, 2015 at 9:20 pm #11011vineethkumarcParticipanthi,
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] = ''; }
March 11, 2015 at 10:39 pm #11021thiruppathiParticipantHi, 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.
March 12, 2015 at 3:09 pm #11027Ligo GeorgeKeymasterYou 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..
March 12, 2015 at 10:00 pm #11029vineethkumarcParticipanthi
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
March 13, 2015 at 9:57 am #11035Ligo GeorgeKeymasterThat error will be related to standard C syntax and usage.
March 15, 2015 at 9:04 pm #11038vineethkumarcParticipantthanks..
I got the latitude and longitude from gps and displayed it on lcd but while sending through GSM,it is not possible.March 16, 2015 at 4:02 pm #11044Ligo GeorgeKeymasterTry 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); }
-
AuthorPosts
- You must be logged in to reply to this topic.