Word Clock with GLCD and PIC18F45K22



Today’s project is a rather unusual one: a word clock implemented using a graphical LCD (GLCD), a PIC18F45K22 microcontroller, all put together on a EasyPIC v7 development board from MikroElektronika.

I have to admit that the idea of making my own word clock bothers me for some time, and I always was too lazy to go to to all that hassle of building it, especially because of the issues related to the mechanical construction. Until one day inspiration come: I can emulate the feeling of a word clock using a GLCD. No mechanical work, and all I needed was already in my inventory. So, all you need is:
  • EasyPIC V7 from MikroElektronika, with 8MHz crystal and PIC18F45k22 microcontroller (standard configuration).
  • 128×64 GLCD, mine has part no. MIKROE-4. Note that this is only a GLCD, without touch capabilities. As such, programming of the clock is made using the buttons on EasyPIC v7.
  • mikroC PRO for PIC full license. A full license is required as the code exceeds the limit of 2kb. I do prefer this compiler as it comes with many libraries, including one for GLCD.
  • Timer Calculator from MikroElektronika software. As I found that I don’t have any RTC click boards, I will use TIMER1 to generate an interrupt every 250ms, and a counter to increment every minute (note to self: order some RTC’s).
  • EasyPIC V7 with PIC18F45K22 microcontroller, 8MHz crystal and 128×64 GLCD
EasyPIC V7 with PIC18F45K22 microcontroller, 8MHz crystal and 128×64 GLCD

In the above picture, you see the EasyPIC v7 with the GLCD installed. Besides this, several jumpers must be set for the software to run correctly. The settings are

  • J17 is set to ground (required for button operation).
  • On the switch from PORTE, pull-ups are activated for pins RE2, RE1 and RE0.
  • J21 is set to disable the piezo buzzer.
  • All switches on SW1 and SW2 are set to disabled (left position).
  • On SW3 the switch corresponding to LEDs connected to ports A/E is set to enabled (right position). All other switches are on the left (disabled).
  • On SW4 the BCK is connected to 5V (switch 6 on the right position). All other switches are on left. This will enable the backlight of the GLCD, on full intensity.

Switches onboard the EasyPIC v7
That is all for the hardware!

The code

Well, now comes the difficult part: writing a word clock code. The code that I propose is written in MikroC, as I take full benefit from having a GLCD library, completed with some nice system fonts. Starting with a picture of a LED-based word clock in my hand, and after some trial and errors I came with the following clock layout:

Word clock display, with all letters on

As I don’t have a RTC, the clock setting is lost when the reset button is pressed or when the power is lost. I turned this into an advantage by writing the code so the clock will enter programming mode when the reset button is pressed or when the power is applied. After we exit the programming mode by pressing RE0 all the buttons are ignored and the clock runs until power is turned off or the reset button is pressed. And here are some pictures of the display when the clock is in programming mode:

Programming menus of the the word clock

As you observe, I used a small 3×5 system font is programming mode to maximize the information on the screen. After that, I will change to a larger 5×8 system font that is easier to read from the distance.

Timings

To generate the timing I used the main clock, running from an external crystal of 8MHz. Obviously, with this clock frequency, with all the prescaling and the 16 bits resolution of the timer, the period of the generated pulsed cannot he higher than 262ms. I set the period to 250ms, at it makes further computation easier. An extra software counter is incremented every time timer overflows, so we can generate the minutes and the hours.

MikroElektronika Timer Calculator

The code

Oh, the mighty code. Here’s the full listing:



By now you have spent several minutes trying to understand how the code works. Here are some extra considerations:

In the programming part, I used the Button function, which performs button debouncing. You might wish to read the mikroC help file for information about the way this function works.

The timer generates an interrupt every 250ms. At every interrupt the variable count is incremented. For a minute we have 60 seconds, and we have four timer overflows every second, thus we have to increment the count for 240 times to reach a full minute. When a minute is reached, the count is reset, and then the minute variable is incremented. Next we check to see if we went over 59. If so, we reset the minutes and we increment the hour, again checking for overflow (which happens when we go over twelve, as the clock is 12h only).

The internal clock works in minutes and hours, but the display is updated every five minutes. This is why I use the variable disp_minute, which is determined as The result if then passed to the Glcd_Word_Clock routine.

The Glcd_Word_Clock routine takes care of emulating the word clock feel. First we clear the GLCD and we show the text IT’S. Then, the disp_minute is evaluated via a series of switch-case statements to determine which text to show on the display. If the disp_minute is below 30, the text PAST is shown. If disp_minute is over 35 the text TO is shown, then the hour is incremented, obviously performing an extra check so the hour cannot go past twelve. Once again a series of switch-case statements is used to display the corresponding text for the hour. Finally, we show the text O’CLOCK.
Name

Air quality,2,Arduino code library,2,Arduino projects,23,Buggy,1,Casual stuff,1,ESP8266,2,MikroElektronika,3,PIC projects,7,Review,26,Robots,1,Tutorial,20,
ltr
item
Electronza: Word Clock with GLCD and PIC18F45K22
Word Clock with GLCD and PIC18F45K22
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPVEnuYxcfG0NCIKq-Z1s32SoIY72Umx9LGT86FYkuivwwLIEf6Vfwupn0DjeJJBF7LM6Fah-PmK5G2-1qOtmar0wiX0xpMVPal_NYeQDuGf48Q3Fd13hCtriH7WIgRTQ71W-3Ch5Zfn84iLoYEtAlOjk5LhOPhUF94uiozgG95yh5-zG_nTR7E54c/w640-h480/all-clock-big.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPVEnuYxcfG0NCIKq-Z1s32SoIY72Umx9LGT86FYkuivwwLIEf6Vfwupn0DjeJJBF7LM6Fah-PmK5G2-1qOtmar0wiX0xpMVPal_NYeQDuGf48Q3Fd13hCtriH7WIgRTQ71W-3Ch5Zfn84iLoYEtAlOjk5LhOPhUF94uiozgG95yh5-zG_nTR7E54c/s72-w640-c-h480/all-clock-big.jpg
Electronza
https://www.electronza.com/2016/01/word-clock-with-glcd-and-pic18f45k22.html
https://www.electronza.com/
https://www.electronza.com/
https://www.electronza.com/2016/01/word-clock-with-glcd-and-pic18f45k22.html
true
4275662725798500575
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content