Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

gps receiver interfacing with microcontroller and displaying data on lcd and pc , Study Guides, Projects, Research of Electronics engineering

Telecommunications

Typology: Study Guides, Projects, Research

2014/2015

Uploaded on 06/05/2015

khanhdon
khanhdon ๐Ÿ‡ป๐Ÿ‡ณ

4 documents

1 / 50

Related documents


Partial preview of the text

Download gps receiver interfacing with microcontroller and displaying data on lcd and pc and more Study Guides, Projects, Research Electronics engineering in PDF only on Docsity! MAE 5483 ADVANCED MECHATRONICS DESIGN TERM PROJECT - SPRING 2012 REPORT GPS Receiver Interfacing With Microcontroller And Displaying Data On LCD And PC SHUVRA BANIK 5/1/2012 SCHOOL OF MECHANICAL AND AEROSPACE ENGINEERING OKLAHOMA STATE UNIVERSITY 1 Abstract The Global Positioning System (GPS) is a navigation system which provides location and time information using satellites orbiting the earth. A GPS receiver can locate satellites and their distances from its position and based on those distances, it uses a simple mathematical calculation called Trilateration by which can provide location information very accurately. GPS receivers are getting very popular nowadays for their simplicity to use. In this project a basic GPS receiver unit has been interfaced with a microcontroller and the data found have been shown in both LCD and PC. 4 Introduction A GPS system is a space-based satellite navigation system developed by U.S. Department of Defense in 1973 which became fully operational in 1994. Itโ€™s basically a constellation of 27 satellites (24 are active at a time and 3 are standby). Each of these satellites makes two complete rotations every day around the Earth in some predefined orbits and the orbits are arranged in such a way that at anytime, anywhere on Earth, there are at least four satellites visible in the sky. Low Power Radio Signal at 1575.42 MHz in the UHF band is used to send signal from satellites to GPS receiver. In this project a Garmin GPS 18 LVC, 5m GPS receiver has been interfaced with a CCS PIC18F4520 Development Kit. Sentences have been sent to GPS receiver to control which output sentences it should transmit. Sentences from the GPS receiver have been parsed with different string manipulations and resulting data have been showed in both LCD and PC. 5 Components Hardware ๏ƒ˜ Breadboard A 3.25X2.125 400PNT breadboard has been used to place the electronic circuits. Figure 1: Breadboard ๏ƒ˜ Wires Wires have been used to connect electronic devices on the breadboard. Figure 2: Wires ๏ƒ˜ GPS Receiver A Garmin GPS 18 LVC, 5m has been used as GPS receiver. Figure 3: Garmin GPS 18 LVC, 5m 6 ๏ƒ˜ LCD Module A 4*20 Serial LCD Module (BPP-420) v4.0 has been used. Figure 4: 4*20 Serial LCD Module (BPP-420) v4.0 ๏ƒ˜ Development Kit One CCS PIC18F4520 Development Kit has been used. Figure 5: Development Kit 9 Project Setup A picture of the final setup is given below. Figure 7: Setup 10 NMEA 0183 Protocol Garmin GPS 18 LVC, 5m uses NMEA 0183 Protocol over its serial interface. NMEA stands for National Marine Electronics Association which set these rules. Here used Baud rate is 4800 and for this particular GPS receiver, frequency is 1 Hz. All sentences received by the GPS sensor starts with a โ€œ$โ€ sign and ends with <CR><LF>, the ASCII characters for carriage return (0D hexadecimal) and line feed (0A hexadecimal). The checksum *hh is used for parity checking data. The parity bytes (hh) are the ASCII representation of the exclusive-or (XOR) sum of all the characters between the โ€œ$โ€ and โ€œ*โ€ characters, non-inclusive. Typical sentences received by the Garmin GPS 18 LVC, 5m are $GPALM, $PGRMI, $PGRMC, $PGRMC1, $PGRMO etc. and typical sentences transmitted by this GPS unit are $GPRMC, $GPGGA, $GPGSA, $GPGSV, $PGRMT etc. But output sentences can be controlled by sending commands through @PGRMO sentence. In this project code, all possible output sentences have been enabled by sending "$PGRMO,,3*74\r\n" sentence to the GPS receiver. Information is stored in these sentences are separated by commas. A typical $GPRMC sentence contains following information. Figure 8: $GPRMC Sentence 11 Initial Programming Strategy RDA Interrupts RDA Interrupts occur when receive data are available in RS232 channel. Sample code for RDA Interrupts given in CCS example files had been modified to read data from GPS receiver and to display in the monitor. Circular / Ring Buffer System was used so that incoming burst of data do not flood memory. This is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. Figure 9: Ring Buffer Used RDA interrupt code is given below. For the GPS receiver used in this project, RDA interrupts didnโ€™t trigger at all. But the code was okay as it was tested for getting interrupts from keyboard. #include <18f4520.h> #include <string.h> #fuses HS,NOLVP,NOWDT,PUT #use delay(clock=20000000) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,STREAM=pc) #use rs232(baud=4800,parity=N,INVERT,rcv=PIN_C3,STREAM=gps,ERRORS) #define BUFFER_SIZE 500 BYTE buffer[BUFFER_SIZE]; BYTE next_in = 0; BYTE next_out = 0; # INT_RDA void serial_isr() 14 $GPGSV,3,1,12,05,04,305,00,06,00,000,00,07,67,350,00,08,34,311,00*75 $GPGSV,3,2,12,09,00,000,00,10,00,000,00,11,00,000,00,12,00,000,00*70 $GPGSV,3,3,12,13,00,000,00,14,00,000,00,15,00,000,00,28,20,254,44*72 $PGRMT,GPS 18LVC - software ver. 2.90,P,P,R,R,P,C,28,R*77 $GPRMC,070837,V,3607.4154,N,09704.1496,W,,,180514,004.9,E*7A $GPGGA,070837,3607.4154,N,09704.1496,W,0,00,,,M,,M,,*42 $GPGSA,A,1,,,,,,,,,,,,,,,*1E $GPGSV,3,1,12,05,04,305,00,06,00,000,00,07,67,350,00,08,34,311,00*75 $GPGSV,3,2,12,09,00,000,00,10,00,000,00,11,00,000,00,12,00,000,00*70 $GPGSV,3,3,12,13,00,000,00,14,00,000,00,15,00,000,00,28,20,254,44*72 $GPRMC,070838,V,3607.4154,N,09704.1496,W,,,180514,004.9,E*75 $GPGGA,070838,3607.4154,N,09704.1496,W,0,00,,,M,,M,,*4D 15 Final Programming Outline This program will show 8 options from 1 to 8 at the beginning to choose any of these in both LCD and PC. Each option represents a GPS sentence received from the GPS receiver. When user chooses any of these options, he/she will get 4 submenus from A to D to see different information of chosen GPS sentence. User will have to choose any of these submenus. This program can handle wrong inputs. When both inputs are got from the user correctly, this program will display chosen options with corresponding strings. Then the program will do checksum calculation and will display result in both LCD and PC. If the checksum calculation is okay, it will proceed and will display the desired GPS sentence. Then it will show the desired information from the desired GPS sentence and finally it will return back to show 8 options again. This loop will continue until the power supply is cut off. Changes Made After Final Presentation Several significant changes have been made after final presentation. These are: ๏ƒ˜ Sending Data To GPS Receiver "$PGRMO,,3*74\r\nโ€ sentence has been sent to GPS receiver to enable all available output sentence. So, now not only data is read from the receiver but also sent to it. PIN_C2 has been used as data transmit pin. Final code shows 8 sentences on the LCD display. ๏ƒ˜ Parity Checking Parity checking has been done by comparing calculated checksum with original checksum to be sure that received sentence is correct. ๏ƒ˜ UTC Time To CST Time Conversion UTC Time is also displayed in CST Time format. After enabling all output sentences, these data streams are repeated over time. Some logged data are given below. Highlighted sentences are new (Not default factory enabled sentences). $PGRMV,,,*72 $PGRMF,,,290412,212300,,3607.8116,N,09704.7553,W,A,0,,,,*36 $PGRMB,,,,,,K,,,*2D $PGRMM,WGS 84*06 $GPRMC,212301,V,3607.8116,N,09704.7553,W,,,290412,004.9,E*73 $GPGGA,212301,3607.8116,N,09704.7553,W,0,00,,,M,,M,,*4E $GPGSA,A,1,,,,,,,,,,,,,,,*1E $GPGSV,3,1,12,03,37,134,00,06,36,113,00,07,23,281,34,10,15,315,00*71 $GPGSV,3,2,12,13,43,319,00,16,65,049,00,19,10,162,00,20,31,216,00*75 $GPGSV,3,3,12,23,76,326,00,30,37,045,00,32,22,189,00,51,47,197,00*72 16 $PGRME,,M,,M,,M*00 $GPGLL,3607.8116,N,09704.7553,W,212301,V*2E $GPVTG,,T,,M,,N,,K*4E $PGRMV,,,*72 $PGRMF,,,290412,212301,,3607.8116,N,09704.7553,W,A,0,,,,*37 $PGRMB,,,,,,K,,,*2D $PGRMM,WGS 84*06 $GPRMC,212302,V,3607.8116,N,09704.7553,W,,,290412,004.9,E*70 $GPGGA,212302,3607.8116,N,09704.7553,W,0,00,,,M,,M,,*4D $GPGSA,A,1,,,,,,,,,,,,,,,*1E $GPGSV,3,1,12,03,37,134,00,06,36,113,00,07,23,281,34,10,15,315,00*71 19 CST Time UTC Time Offset 7 PM 00 +7 8 PM 01 9 PM 02 10 PM 03 11 PM 04 12 AM 05 1 AM 06 -5 2 AM 07 3 AM 08 4 AM 09 5 AM 10 6 AM 11 7 AM 12 8 AM 13 9 AM 14 10 AM 15 11 AM 16 12 PM 17 1 PM 18 -17 2 PM 19 3 PM 20 4 PM 21 5 PM 22 6 PM 23 LCD Functions There are four functions for LCD display. These are void clear_func(), backlight_on(), new_line() and lcd_positioner(). ๏ƒ˜ clear_func() It clears LCD screen. ๏ƒ˜ backlight_on() It turns on the backlight of LCD. ๏ƒ˜ new_line() Move cursor to new line. ๏ƒ˜ lcd_positioner() It places cursor on right hand side of the LCD to print options from 5 to 8. 20 All Functions Summary These are the functions altogether used in the final code. Functions Main Functi on Option, Display Related Functions GPS Parsing Functions Other Supportive Functions LCD Functions 1) gps_output_ct rl_func() 2) option_showi ng_func() 3) select_func() 1) gps_input() 2) sub_string_fin der() 1) checksum_ch ecker() 2) atoi_hex() 3) utc_to_cst_ti me_converter () 1) clear_func( ) 2) backlight_o n() 3) new_line() 4) lcd_positio ner() 21 Final Output LCD Display One complete operation displayed on LCD has shown here. 24 PC Display One complete operation displayed on PC has shown here. GPS Choose 1,2,3,4,5,6,7 or 8 & then A,B,C or D 1. $GPRMC 2. $GPGGA 3. $GPGSA 4. $GPGSV 5. $PGRMT 6. $GPVTG 7. $GPGLL 8. $PGRMF r Wrong option! Please try again.... 1. $GPRMC 2. $GPGGA 3. $GPGSA 25 4. $GPGSV 5. $PGRMT 6. $GPVTG 7. $GPGLL 8. $PGRMF 2 A. UTC Time B. Latitude C. Longitude D. No. of Satellites g Wrong option! Please try again.... A. UTC Time B. Latitude C. Longitude D. No. of Satellites B You chose option 2B $GPGGA Latitude Calculated checksum in decimal 126 Original checksum in decimal 126 EQUAL! Selected NMEA 0183 Sentence => $GPGGA,094756,3607.7943,N,09704.7737,W,1,04,5.7,319.5,M,-26.3,M,,*7E 3607.7943 ddmm.mmmm N Thanks! 26 1. $GPRMC 2. $GPGGA 3. $GPGSA 4. $GPGSV 5. $PGRMT 6. $GPVTG 7. $GPGLL 8. $PGRMF 29 Appendix Final Code /* GPS_FINAL.C ---------------------- by Shuvra Banik, MS Student, MAE, Oklahoma State University ------------------------------------------------------------------------------------- Program Summary: --------------------------- This program will show 8 options from 1 to 8 at the beginning to choose any of these in both LCD and PC. Each option represents a GPS sentence received from the GPS receiver. When user chooses any of these options, he/she will get 4 submenus from A to D to see different information of chosen GPS sentence. User will have to choose any of these submenus. This program can handle wrong inputs. When both inputs are got from the user correctly, this program will display chosen options with corresponding strings. Then the program will do checksum calculation and will display result in both LCD and PC. If the checksum calculation is okay, it will proceed and will display the desired GPS sentence. Then it will show the desired information from the desired GPS sentence and finally it will return back to show 8 options again. This loop will continue until the power supply is cut off. Connection Settings: ----------------------------- GPS Receiver (Garmin GPS 18 LVC, 5m): ------------------------------------------------------- Black (3) ---------- Ground of Microcontroller Red ---------- 5 V of Microcontroller White ---------- PIN_C3 of Microcontroller (Signal Output) Green ---------- PIN_C2 of Microcontroller (Signal Input) Yellow ---------- Not Used LCD Module (4*20 Serial LCD Module (BPP-420) v4.0): --------------------------------------------------------------------------- Black ---------- Ground of Microcontroller Black ---------- 5 V of Microcontroller White ---------- PIN_C0 of Microcontroller */ #include <18f4520.h> // Device header file 30 #include <string.h> // Standard string operations #include <stdlib.h> // String to numer conversion operations #fuses HS,NOLVP,NOWDT,PUT // Set fuses #use delay(clock=20000000) // 20 MHz clock /*----- Serial communications -----*/ #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,STREAM=pc) // PC #use rs232(baud=4800,parity=N,INVERT,xmit=PIN_C2,rcv=PIN_C3,STREAM=gps,ERRORS) // GPS #use rs232(baud=9600,parity=N,xmit=PIN_C0,INVERT,STREAM=lcd) // LCD /*----- LCD constants -----*/ #define CLR 12 #define BLON 14 #define CR 13 #define CURSOR_POSITION_ENTRY 16 #define CURSOR_POSITION_BASE 64 #define REQ_CURSOR_POSITION 11 /*----- Global string lengths -----*/ #define MAX_BUFFER 82 #define SUB_BUFFER 11 #define OPTION_STRING_LENGTH 20 #define MAX_UNIT_STRING 20 #define MAX_TIME_STRING 7 /*----- Global string declarations -----*/ char store_data[MAX_BUFFER]; char sub_string[SUB_BUFFER]; char option_string[OPTION_STRING_LENGTH]; char unit_string[MAX_UNIT_STRING]; char cst_time_string[MAX_TIME_STRING]; /*----- Global integer declarations -----*/ int comma_position; int sub_string_comma_position=0; /*----- Option, display related function declarations -----*/ void gps_output_ctrl_func(void); char option_showing_func(char start_char,char end_char,char selector_char); void select_func(char opt1,char opt2,int position_flag); 31 /*----- GPS parsing function declarations -----*/ void gps_input(*checker); void sub_string_finder(void); /*----- Other supportive function declarations -----*/ int checksum_checker(void); unsigned int8 atoi_hex(char *string); void utc_to_cst_time_converter(char *sub_string); /*----- LCD function declarations -----*/ void clear_func(void); void backlight_on(void); void new_line(void); void lcd_positioner(int position_increment); void main() { // Main function variable declarations char opt1,opt2,dummy='0'; char checker[7]; char utc_time_string[]="hhmmss UTC"; clear_func(); // Clears up LCD screen delay_ms(2000); // Time given to turn on back light at the beginning backlight_on(); // Turns on backlight fprintf(pc,"\r\nGPS\r\n "); fprintf(lcd,"GPS"); new_line(); // Moves to new line in LCD fprintf(pc,"\r\nChoose 1,2,3,4,5,6,7 or 8 & then A,B,C or D\r\n "); fprintf(lcd,"Choose 1,2,3,4,5,6, 7 or 8 & then A,B,C or D"); gps_output_ctrl_func(); // Controls which sentences GPS unit should transmit while(TRUE) { clear_func(); opt1=option_showing_func('1','8',dummy); // Displays 8 options from 1 to 8 for 8 GPS sentences // Gets opt1 opt2=option_showing_func('A','D',opt1); // Displays 4 submenus from A to D under each sentence 34 { // option_showing_func variable declarations char i,option; int position_increment=0; // Initially no position_increment is needed for(;;) { for(i=start_char;i<end_char+1;++i) { fprintf(pc,"\r\n%c. ",i); // For printing on right hand side of LCD if(!(i>='5'&& i<='8')) // i!='5' && i!='6' && i!='7' && i!='8' { fprintf(lcd,"%c. ",i); } if (selector_char=='0') { select_func(i,selector_char,0); // Sending position_flag=0 // Pulls out appropriate option_string } else { select_func(selector_char,i,0); // Sending position_flag=0 // Pulls out appropriate option_string } fprintf(pc,option_string); fprintf(pc,"\r\n "); // For printing on right hand side of LCD if(!(i>='5'&& i<='8')) { fprintf(lcd,option_string); new_line(); } else { lcd_positioner(position_increment); // Positions cursor at certain location on LCD fprintf(lcd,"%c. ",i); fprintf(lcd,option_string); position_increment=position_increment+20; // Prints on right hand side of LCD } } option=fgetc(pc); 35 clear_func(); if(option>=start_char && option<=end_char) { break; } else { fprintf(pc,"\r\nWrong option! Please try again....\r\n "); fprintf(lcd,"Wrong option! Please try again...."); delay_ms(3000); clear_func(); position_increment=0; // Using it cause if not used, for two // consecutive wrong input, alignment in LCD can be changed continue; // Sends back user to options again for wrong input } } return option; // Sends user input to Main function } // For each option from 1 to 8, there are 4 submenus from A to D // Pulls out appropriate option_string, unit_string // Pulls out appropriate comma_position, sub_string_comma_position void select_func(char opt1,char opt2,int position_flag) { switch(opt1) { case '1': strcpy(option_string,"$GPRMC"); switch(opt2) { case 'A': strcpy(option_string,"UTC Time"); if(position_flag) { strcpy(unit_string,"hhmmss UTC"); comma_position=1; } break; case 'B': strcpy(option_string,"Date"); if(position_flag) { strcpy(unit_string,"ddmmyy UTC"); comma_position=9; 36 } break; case 'C': strcpy(option_string,"Latitude"); if(position_flag) { strcpy(unit_string,"ddmm.mmm"); comma_position=3; sub_string_comma_position=4; } break; case 'D': strcpy(option_string,"Longitude"); if(position_flag) { strcpy(unit_string,"ddmm.mmm"); comma_position=5; sub_string_comma_position=6; } break; } break; case '2': strcpy(option_string,"$GPGGA"); switch(opt2) { case 'A': strcpy(option_string,"UTC Time"); if(position_flag) { strcpy(unit_string,"hhmmss UTC"); comma_position=1; } break; case 'B': strcpy(option_string,"Latitude"); if(position_flag) { strcpy(unit_string,"ddmm.mmmm"); 39 comma_position=5; } break; case 'C': strcpy(option_string,"Sat. Azimuth"); if(position_flag) { strcpy(unit_string,"Degrees"); comma_position=6; } break; case 'D': strcpy(option_string,"Signal/Noise"); if(position_flag) { strcpy(unit_string,"dB"); comma_position=7; } break; } break; case '5': strcpy(option_string,"$PGRMT"); switch(opt2) { case 'A': strcpy(option_string,"Model & Version"); if(position_flag) { strcpy(unit_string,""); comma_position=1; } break; case 'B': strcpy(option_string,"Sensor Temp(C)"); if(position_flag) { 40 strcpy(unit_string,"Degree C"); comma_position=8; } break; case 'C': strcpy(option_string,"Osc. Drift"); if(position_flag) { strcpy(unit_string,"P=Pass,F=High Drift"); comma_position=6; } break; case 'D': strcpy(option_string,"Stored Data Lost"); if(position_flag) { strcpy(unit_string,"R=Retained,L=Lost"); comma_position=4; } break; } break; case '6': strcpy(option_string,"$GPVTG"); switch(opt2) { case 'A': strcpy(option_string,"Dead Option!"); if(position_flag) { strcpy(unit_string,""); comma_position=0; } break; case 'B': strcpy(option_string,"Dead Option!"); if(position_flag) { strcpy(unit_string,""); 41 comma_position=0; } break; case 'C': strcpy(option_string,"Dead Option!"); if(position_flag) { strcpy(unit_string,""); comma_position=0; } break; case 'D': strcpy(option_string,"Dead Option!"); if(position_flag) { strcpy(unit_string,""); comma_position=0; } break; } break; case '7': strcpy(option_string,"$GPGLL"); switch(opt2) { case 'A': strcpy(option_string,"Latitude"); if(position_flag) { strcpy(unit_string,"ddmm.mmm"); comma_position=1; sub_string_comma_position=2; } break; case 'B': strcpy(option_string,"Longitude"); if(position_flag) { strcpy(unit_string,"ddmm.mmm"); 44 c=fgetc(gps); if(c=='$') // Starts storing data if the input character is '$' state=1; if(state) { store_data[i]=c; if(i<6) temp[i]=c; ++i; if (i==6) { temp[i]='\0'; if((strcmp(temp,checker))!=0) // Compares if sentence being stored is desired {i=0; state=0;} } if(state && c=='\r') // Ends storing if '\r' is received { store_data[i]='\0'; i=0; state=0; checksum_result=checksum_checker(); // Gets checksum_result from checksum_checker() // Compares original checksum with calculated checksum for parity checking if(checksum_result) { break; } else { continue; } } } } } // Finds desired data like time or latitude etc. from store_data string void sub_string_finder(void) { //sub_string_finder variable declarations int i,j=0,count=0,store_data_length; store_data_length=strlen(store_data); // If comma_position is 0, no data is available to display 45 if (comma_position==0) { strcpy(sub_string,"Not Available"); return; } for (i=0;i<store_data_length;++i) { if(store_data[i]==',') ++count; // Checks if current comma_position equals to desired comma_position if (count==comma_position) { ++i; while(store_data[i]!=',') // Stores data until next ',' is found { sub_string[j]=store_data[i]; ++j; ++i; } sub_string[j]='\0'; // Closing sub_string break; } } } /*----- Other supportive functions -----*/ // Compares original checksum with calculated checksum for parity checking int checksum_checker() { // checksum_checker() variable declarations int i=0; int checksum_result; unsigned int8 checksum=0; unsigned int8 original_checksum; char *store_data_ptr=store_data+1; // Points 2nd character of store_data string char original_checksum_string[3]; // Xoring loop until '*' is found in store_data string while (*store_data_ptr != '*') 46 { checksum ^= *store_data_ptr; store_data_ptr++; } clear_func(); // Prints calculated checksum fprintf(pc,"\r\nCalculated checksum in decimal %d\r\n ", checksum); fprintf(lcd,"Cal. checksum %d", checksum); new_line(); store_data_ptr++; //Now pointing checksum data in store_data string // Getting original checksum from store_data in string format while (*store_data_ptr != '\0') { original_checksum_string[i]=*store_data_ptr; store_data_ptr++; ++i; } original_checksum_string[i]='\0'; // Converts a string of two hex characters to a unsigned int8 original_checksum=atoi_hex(original_checksum_string); // Prints original checksum fprintf(pc,"\r\nOriginal checksum in decimal %d\r\n ", original_checksum); fprintf(lcd,"Ori. checksum %d", original_checksum); new_line(); // Compares original checksum with calculated checksum for parity checking if(checksum==original_checksum) { fprintf(pc,"\r\nEQUAL!\r\n "); fprintf(lcd,"EQUAL!"); delay_ms(5000); clear_func(); checksum_result=1; } else { fprintf(pc,"\r\nNOT Equal!\r\n "); fprintf(lcd,"NOT Equal!"); fprintf(pc,"\r\nTrying...\r\n "); new_line();
Docsity logo



Copyright ยฉ 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved