Now you need a GPS system

5 JULY 2010

The Global Positioning System (GPS) is one of the leading technologies today used for navigation purposes. It is widely used in automotive navigation system. Connection between a GPS receiver and the microcontroller as well as determination of latitude and longitude will be described here.

By Dusan Mihajlovic – Hardware Department

The Global Positioning System (GPS) is based on a large number of satellites emitting microwave signals by means of which GPS receivers can determine their current location, time or velocity. GPS receivers can communicate with the microcontroller or PC in different ways. A common one is via serial port, whereas the most commonly used protocol for transmitting data is a NMEA protocol.

Principal of operation
The NMEA protocol is based on sentences. Every sentence starts with the $ sign (ASCII 36) and terminates with signs starting new lines such as CR (ASCII 13) and LF (ASCII 10). The meaning of the whole sentence depends on the first word.
For example, a sentence starting with $GPGLL gives information about latitude and longitude, exact time (Universal Coordinated Time), data validity (A – Active or V – Void) and checksum enabling you to check whether data is regularly received. All data are separated by a comma ‘,’. Each second a set of NMEA sentences are sent to the microcontroller. In the event that data on latitude and longitude are not fixed (if a GPS receiver fails to determine its location) or when other data is not determined, the GPS receiver will keep on transmitting the same set of sentences, now reduced by missing data.

Here is a sentence generated by the GPS receiver which failed to determine its location:

$GPGLL,,,,,,V,*2A

An example of a complete NMEA sentence is given in figure below:

Hardware
Connection between the microcontroller and GPS receiver is very simple. It is necessary to provide only two lines RX and TX for this purpose. Refer to the Schematic 1. The RX line is used for sending data from a GPS receiver to the microcontroller, while the TX line can be used for sending specific commands from the microcontroller to the GPS receiver.

Schematic 1: Connecting the LEA-5S module to a PIC18F4520

The U-Blox LED-5S GPS receiver is used in this project. Similar to most GPS receivers, the power supply voltage of this receiver is 3V.
Since the PIC18F4520 microcontroller uses 5V power supply for its operation, it is necessary to use a voltage level translator to convert the voltage level of logic one from 3.3V to 5V. In this example, a graphic display in resolution of 128×64 pixels displays a world map with the cursor pointing to your location.

Software
As you can see, the program code being dumped into the microcontroller is very short. Nearly half a code makes a bitmap converted into appropriate set of data. Such conversion enables the microcontroller to display the map. The rest of code consists of receiving NMEA sentences from the GPS receiver, calculating latitude and longitude, scaling data to match the display resolution of 128×64 pixels and positioning cursor on the specified location.
Functions used in the program
Glcd_box() Draw filled box
Glcd_circle() Draw circle
Glcd_Dot() Draw dot*
Glcd_Fill() Delete/fill display*
Glcd_H_Line() Draw horizontal line
Glcd_Image() Import image*
Glcd_Init() LCD display initialization*
Glcd_Line() Draw line
Glcd_Read_Data() Read data from LCD
Glcd_Rectangle() Draw rectangle
Glcd_Set_Font() Select font*
Glcd_Set_Page() Select page
Glcd_Set_Side() Select side of display
Glcd_Set_X() Determine X coordinate
Glcd_V_line() Draw vertical line
Glcd_Write_Char() Write character
Glcd_Write_Data() Write data
Glcd_Write_Text() Write text
* Glcd library functions used in the program

Other mikroC PRO for PIC functions used in program:
Usart_Init() strstr()
Usart_Read() Delay_ms()

GO TO
Code for this example written for PIC® microcontrollers in C, Basic and Pascal as well as the programs written for dsPIC® and AVR® microcontrollers can be found on our web site: www.mikroe.com/en/article/

Comments

GIFOM says:

i need programmer…please….

Leave a Reply

Your email address will not be published. Required fields are marked *

  • We use your personal data ONLY to respond to your comments/requests.
  • To receive responses that are appropriate to your requests, we may transfer your email address and your name to the author of the article.
  • For more information on our Privacy Policy and Personal Data Processing, please visit the page: Privacy Policy (GDPR) & Cookies.
  • If you have any questions or concerns regarding the way we process your personal data, you can contact our Data Protection Officer at: gdpr@esp2000.ro
  • Subscribe to our magazine newsletter