GPS Real time clock using PIC18F4550 and NEO-6M module

After interfacing the PIC18F4550 microcontroller with NEO-6M GPS module, now I’m going to show how to build a real time clock with local time where time and date are displayed on 20×4 LCD screen.
In this project the microcontroller receives time data from the GPS module (the GPS module receives data from satellites) and prints it on the 20×4 LCD.

Related Projects:
Last PIC18F4550 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:
GPS Module interfacing with PIC18F4550 microcontroller

PIC18F4550 GPS real time clock & calendar NEO-6M LCD

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

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

GPS Real time clock using PIC18F4550 and NEO-6M module circuit:
The following image shows the circuit schematic of the project.

PIC18F4550 GPS Real time clock NEO-6M 20x4 LCD

(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 PIC18F4550 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 PIC18F4550 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

GPS Real time clock using PIC18F4550 and NEO-6M module C code:
The following C code 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:

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


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

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