Posted on Leave a comment

Realtime Clock with 18F2550

I am trying to make use of the previous circuit on connecting LED display to 18F2550, and combining this with Real time clock module DS3231. So here are the diagram of the connection:

Here are the list of parts used in this project:

  • 18F2550 USB development board
  • Realtime clock DS3231
  • Button cell battery CR2032 (for realtime clock)
  • LCD Display
  • 10K ohm variable resistor (to control the brightness of LCD display)
  • 200 ohm pull up resistor

The 18F2550 USB development board can be shown below:

This board comes loaded with boot loader to allow easy loading of the firmware code. I am using the MPLAB IDE v8.92 to compile and build the code for the USB development board.

I am also using the previously ported LCD display code to use in this project.

Connect Everything together

First we connect the LCD Display to the Development board. We are only using 4 bit for the data transfer so here are the detail connection of the LCD Display:

  • RS LCD —- C6 Dev Board
  • EN LCD —- C7 Dev Board
  • D4 LCD —- A0 Dev Board
  • D5 LCD —- A1 Dev Board
  • D6 LCD —- A2 Dev Board
  • D7 LCD —- A3 Dev Board

You will also need to connect a pull up resistor to Anode pin of LCD display before connecting to +5V and Middle of 10k resistor to VO pin of LCD display, while the other ends of the 10K resistor is connected to VCC and GND respectively.

Test the LCD connection.

Once you had connected the LCD Display to 18F2550 development board you can load the demo display program. To load the demo program (C18-BOLT-LCD-MESSAGE-SCROLLING.HEX), you can use the loader program “MiEUSBHIDLoader.exe“. This program will display a scrolling Alphabet in the first row and numbers on the second row of the LCD Display, please make sure that this is working properly prior to continuing to the next step.

Connecting the Real time clock

First connect the button cell CR2032 to the realtime clock module DS3231. Then connect the DS3231 to the USB development board. To connect the real time clock DS3231 to the 18F2550 USB Development board use the following connection:

  • SDA RTC —- B0 Dev Board
  • SCL RTC —- B1 Dev Board

You will also need to connect the VCC of DS3231 to the 5V and GND to the ground of the 18F2550 Development board. Once this is done you can now upload the RTC clock program. You might want to recompile the code to set the date and time the first time you are loading the code

// uncomment the following to set the date and time
DS3231_SetDate(29,03,19); // setting the date to 29-Mar-2019
DS3231_SetTime(00,19,01); // setting the time to 00:19:01

Once the code is loaded, the date and time is now saved in the DS3231 module. As long as the button cell CR2032 is connected to the DS3231 module, the date and time will be retained. Now you need to recompile the code again with the above code uncommented, this is to ensure that every time you reset the USB development board, it will not reset the date and time of RTC module back to the date time above.

Please drop me a line and share this post if you like it, and let me know what I can improve on. Stay tune for the next revision that will include buttons to set the date and time.

Leave a Reply

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