GPS Clock with PIC microcontroller and NEO-6M module | mikroC Projects

After interfacing the PIC16F887 microcontroller with NEO-6M GPS module, now I’m going to show how to build a GPS clock with local time where time and date are displayed on 20×4 LCD screen.
In this project the microcontroller receives time and date data from the GPS module (the GPS module receives data from satellites) and print it on the 20×4 LCD. The compiler used in this project is mikroElektronika mikroC PRO for PIC.   —  GPS: Global Positioning System  —

Related Projects:
Last PIC16F887 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.  —  UTC: Universal Time Coordinated  —
Interfacing PIC microcontroller with GPS module | mikroC Projects

PIC16F887 GPS Clock with NEO-6M module and 20x4 LCD

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

  • PIC16F887 microcontroller
  • NEO-6M GPS module
  • 20×4 LCD screen
  • 10k ohm variable resistor (or potentiometer)
  • 330 ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

GPS Clock using PIC16F887 and NEO-6M module circuit:
The following image shows the circuit schematic of the project.

PIC16F887 GPS Clock with NEO-6M module and 20x4 LCD circuit

(All grounded terminal 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 PIC16F887 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
E  —> RD1 pin
D4 —> RD2 pin
D5 —> RD3 pin
D6 —> RD4 pin
D7 —> RD5 pin
VSS, RW, 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 PIC16F887 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

GPS Clock using PIC16F887 and NEO-6M module C code:
The following C code is for mikroC PRO for PIC compiler.

In this project I used a small GPS library for mikroC compiler, 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_mikroc.c“:
mikroC GPS Library download

after the download, add the library file (GPS_mikroc.c) to project folder.

As known, the GPS module always gives 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 mikroC PRO for PIC time library (built-in library). But we’ve to add the library header to the project folder, the library header named timelib.h, it is located in examples folder of mikroC installation folder (for example, C:\Program Files (x86)\MikroElektronika\mikroC PRO for PIC\Examples\Other\Time).
Or you can download it from the following link:
timelib.h

To be able to convert the UTC standard time into our time zone (local time), first we’ve to convert the UTC time 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:
UART1_Data_Ready(): 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 with 2 digits (0 – 99)

mikroC 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 TimeStruct (structure type), I named this variable: utc_time. This variable is a collection of 7 variables, 6 of them are required (the 7th variable is utc_time.wd which is day of the week, not needed here):
utc_time.hh, utc_time.mn, utc_time.ss, utc_time.md, utc_time.mo and utc_time.yy .
utc_time.mn has to be between 1 and 12. utc_time.yy is 4-digit year (2018, 2019, 2020 …).

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 long (4 byte signed number):
unix_time = Time_dateToEpoch(&utc_time) ;

Returning from the UNIX time to our zone time and date is also simple, here an other variable of type TimeStruct is used, I used a variable named: my_time. This variable is also a collection of 7 variables:
my_time.hh, my_time.mn, my_time.ss, my_time.md, my_time.mo, my_time.yy and my_time.wd.
The last variable is day of the week between 0 and 6 (0 for Monday).
my_time.md is day of month (1-31)
my_time.mo is the month (1-12)

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

Full mikroC code:
Configuration words:
CONFIG1 = 0x2CD4
CONFIG2 = 0x0700

The result of this project should be as shown in the following video where PIC16F877A is used:

3 thoughts on “GPS Clock with PIC microcontroller and NEO-6M module | mikroC Projects”

  1. sorry but it throws me an error, the strcmp variable does not have its identifier declared, I already tried with some types but I cannot solve it, could you please advise me

  2. Good morning, I’m working on this and it seems interesting. But I keep getting undeclared identifier for GPS Read, utc_time, GPS Hour etc

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