GPS Clock with PIC16F877A and NEO-6M module

This topic shows how to build a GPS real time clock using PIC16F877A microcontroller and NEO-6M GPS module, other modules should also work. The microcontroller reads time and date from the GPS module (the GPS module receives data from satellites) and display it on a 20×4 LCD screen.

Related Projects:
Last PIC16F877A project, I made a simple interfacing of this microcontroller with NEO-6M GPS module in order to get position, altitude, time (UTC), date, speed, number of satellites and course, project page link is below:
Interfacing PIC16F877A with NEO-6M GPS module

PIC16F877A GPS clock with NEO-6M GPS module

Hardware Required:
To build this project, the following components are needed:

  • PIC16F877A microcontroller
  • NEO-6M GPS module
  • 20×4 LCD screen
  • 8 MHz crystal oscillator
  • 2 x 22pF ceramic capacitor
  • 10k ohm variable resistor (or potentiometer)
  • 330 ohm resistor
  • 10k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

GPS Clock with PIC16F877A and NEO-6M module circuit:
The following image shows circuit diagram of the project.

PIC16F877A GPS clock NEO-6M GPS module 20x4 LCD

(All grounded terminals are connected together)

The NEO-6M GPS module board has 4 pins connected as follows:
GND (Ground) pin connected to circuit GND
TX pin goes to PIC16F877A RX (RC7) pin (pin #26)
RX pin is not connected (there is no need to send data from the microcontroller to the GPS module)
VCC pin goes to circuit +5V pin.

The 20×4 LCD screen is used to display the real time clock time and date where:
RS —> RD0 pin
RW —> RD1 pin
E  —> RD2pin
D4 —> RD3 pin
D5 —> RD4 pin
D6 —> RD5 pin
D7 —> RD6 pin
VSS, D0, D1, D2, D3 and K are connected to circuit GND (ground)
VEE to the variable resistor (or potentiometer) output pin
VDD to +5V and A to +5V through 330 ohm resistor

VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

In this project the PIC16F877A microcontroller runs with 8 MHz crystal oscillator.

GPS Clock with PIC16F877A and NEO-6M module code:
The C code below is for CCS C compiler, it was tested with version 5.051.

In this project I used a small GPS library, this library decodes NMEA sentence that the microcontroller receive from the GPS module, therefore getting time and date is more easier.
GPS Library for CCS C compiler downloaded link is the one below, library full name is “GPS_Lib.c“:
GPS Library download

after the download, add the library file (GPS_Lib.c) to project folder or CCS C compiler drivers folder.

As known the GPS module always gives a UTC time and date which may need to be converted to our time zone (for example UTC + 1). To do the conversion of time we can use CCS C time library (built-in library), time library files are time.h and time.c which are located in CCS C drivers folder.

To be able to convert the UTC standard time into our time zone, first we’ve to convert that time (UTC) into UNIX time (also known UNIX Epoch time or POSIX time ) which is the number of seconds that have elapsed since 00:00:00 UTC, 1 January 1970.

After we get the UNIX Epoch time we add our time offset to it (plus or minus), for example for UTC + 1 time zone we add 3600 seconds, for UTC – 5 we add -18000 seconds and so on.

After that we converter the ‘new’ UNIX time into our zone time and date.

Functions used in the code:
kbhit(): returns 1 if a character has been received by the MCU.

GPS library functions:
GPSRead(): returns 1 if the GPS data (NMEA sentences) have been received and parsed with successful.
GPSHour(): returns hours from the decoded GPS data (0 – 23)
GPSMinute(): returns minutes (0 – 59)
GPSSecond(): returns seconds (0 – 59)
GPSDay(): returns day of month (1 – 31)
GPSMonth(): returns month (1 – 12)
GPSYear(): returns year, ones and tens (0 – 99)

CCS C Time library functions:
First we need to save the UTC time and date (in order to convert it to UNIX time) to a variable of type struct_tm (structure type), I named this variable as: utc_time. This variable is a collection of 8 variables, 6 of them are required:
utc_time.tm_hour, utc_time.tm_min, utc_time.tm_sec, utc_time.tm_mday, utc_time.tm_mon and utc_time.tm_year.
utc_time.tm_mon has to be between 0 and 11. utc_time.tm_year is number of years starting from 1900 (for example 118 for 2018).

Now we can convert the UTC time to UNIX time with the following function where the converted UNIX time is saved to unix_time variable of type time_t (signed int32):
unix_time = mktime(&utc_time);

Returning from the UNIX time to our zone time and date is also simple, here an other variable of type struct_tm is used, I used a variable named: my_time. This variable is also a collection of 8 variables, 7 of them are used:
my_time->tm_hour, my_time->tm_min, my_time->tm_sec, my_time->tm_mday, my_time->tm_mon, my_time->tm_year and my_time->tm_wday.
The last variable is day of week between 0 and 6 (0 for Sunday).
tm_mday is day of month (1-31)
tm_mon is the month (0-11)

Our zone time and date are stored to the variable my_time using the function:
my_time = localtime(&unix_time);

CCS C code:

GPS Clock with PIC16F877A and NEO-6M module video:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

2 thoughts on “GPS Clock with PIC16F877A and NEO-6M module”

  1. I missed the link above – Interfacing PIC16F877A with NEO-6M GPS module – which answered my questions – thanks again!

  2. Thank you for this great project. I will be building a GPS clock soon. I do not know the connection or the hardware to load the code to the processor from a PC. I have only used Arduino processors in the past. Thank you for any assistance.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top