Interfacing GPS with 8051

Tags: Interfacing Gps With 8051, Gps C Source Code,Gps Interfacing With 8051,Gps Configuration Settings,,
Overall rating
8051 Primer Board

The 8051 Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s 8051 (89V51RD2), 8051 Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.

GPS (Global Positioning Systems)

The Global Positioning System (GPS) is a space-based satellite navigation system that provides location and time information in all weather, anywhere on or near the Earth, where there is an unobstructed line of sight to four or more GPS satellites.

Interfacing GPS

Fig. 1 shows how to interface the GPS with microcontroller. The GPS module continuously transmits serial data (RS232 protocol) in the form of sentences according to NMEA standards. The latitude and longitude values of the location are contained in the GPGGA sentence (refer NMEA format).To communicate over UART or USART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface UART with 8051, we just need the basic signals.


Fig. 1 Interfacing GPS to Microcontroller

Interfacing GPS with 8051

We now want to receive data from satellite to 8051 Primer Board by using GPS module through UART0. The serial data is taken from the GPS module through MAX232 into the SBUF register of 8051 microcontroller (refer serial interfacing with 8051). The serial data from the GPS receiver is taken by using the Serial Interrupt of the controller. This data consists of a sequence of NMEA sentences from which GPGGA sentence is identified and processed.

Pin Assignment with 8051



UART DB-9 Connector



Serial Port Section















Circuit Diagram to Interface GPS with 8051


Source Code

The first six bytes of the data received are compared with the pre-stored string and if matched then only data is further accounted for; otherwise the process is repeated again. From the comma delimited GPGGA sentence, latitude and longitude positions are extracted by finding the respective comma positions and extracting the data.

C Program to receives data from satellite to 8051


Title : Program to receive data from satellite to 8051 through UART0




#include<reg51.h>                      //Define 8051 Registers


void serial(void);             //Serial Communication Register

void DelayMs(unsigned int);                 //Delay Function


unsigned int i,j;

unsigned char b[25],d;



//           Main Program


void main()


    EA=1;                     //Enable All Interrupt

    ES=1;                     //Enable Serial Port Interrupt

    serial();                 //Serial Communication

         while(1);             //Loop Forever




//       Serial Communication Register Initialisation


void serial(void)


    TMOD=0X20;                //Timer1, Mode2

    SCON=0X50;                //Serial Mode1, Receive Enable

    TH1=0XFD;                 //Baud Rate 9600bps

    TR1=1;                    //Timer1 ON




//       Serial Interrupt Function


void serin (void) interrupt 4          //Serial Port Interrupt


    if(RI==1)                 //Receive Interrupt Gets Enabled

    {                              //after Stop Bit get Received

         d=SBUF;      //Serial Buffer value moved to a variable



         DelayMs(20);              //Delay Function



    SCON=0X50;   //Initialising Receive and Transmit Interrupt




//               Delay Function


void DelayMs(unsigned int k)


    unsigned int i;





To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Keil, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without 8051 Primer Board.

The Flash Magic software is used to download the hex file into your microcontroller IC 8051 through UART0.

Testing the GPS with 8051

Give +5V power supply to 8051 Primer Board; connect +5V adapter with GPS module is connected with the 8051 Primer Board. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show some text messages.

If you are not reading any data from UART0, then you just check the jumper connections & just check the serial cable is working. Otherwise you just check the code with debugging mode in Keil.

If you want to see more details about debugging just see the videos in below link.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,
       -  User Manual of 8051 Primer Board.
       -  Tutorial of how to create & Debug a project in KEIL.
       -  Interfacing UART with 8051.

Join the World's Largest Technical Community

we respect your privacy.