Clock with LCD and PIC 16F877

ATTENTION: Who created this or other projects on this web site, please can send me on my email photos of his accomplishments? I would like to put it here on-line so that they are visible and can serve as a starting point for new ideas, different realizations or changes, following in this way the spirit of this site which is in favor of disclosure and knowledge of electronics free of charge.
Also, if you, while sending photos of your prototypes, authorize me to put on-line together with the photos at least your name and your email, you will be contacted or you can contact another user who made the same project in order to do together of constructive confrontation.
Thank you in advance, Tony


Introduction:

Given the excellent results obtained with the design of the previous clock with LCD driven by ST6, I thought to design another one, this time with a PIC microcontroller and a bit 'more sophisticated.


Specifications and operation:

White on blue LCD display with 4 lines and 20 characters on which the following data are displayed. (Can be used any compatible display).
Line 1: day, month, and year
Line 2: day of the week (eg Mon for Monday), hours, minutes and seconds
Line 3: if any party or birthday and setup menus are displayed as a description of the various alarm mode.
Line 4: the three alarm clocks with setting method or written Snooze with the display of the remaining time.


Buttons:
PL1 = Input Menu setting clock and alarm clocks, exit the menu and turn off the sounding alarm.
PL2 = Switch to the next field in the clock setting mode
PL3 = Increase in the current field in the clock setting mode
PL4 = Decrease in the current field in the clock setting mode
PL5 = If the alarm is sounding, turn off the alarm by activating the snooze mode, otherwise it increases or decreases the brightness of the LCD.


When you turn the clock displays the copyright for 5 seconds, then displays the clock / calendar as described above.

Pressing the button PL1 you enter the clock setting mode, the display is blocked but the counting of time by the clock continues, in fact if you exit the menu without saving the settings for the clock, it resumes its normal operation.

As you enter the clock setting mode, the cursor flashes on the day. The possibilities are: Press to increase the day PL3, PL4 Press to decrement the day, PL2 Press to move to the next field (in this case the month) or PL1 Press to display the menu output. Moving in this way it is possible to set all functions of the watch bearing in mind that the exit menu, allows you to update the clock separately from alarm clocks, in fact you must set the clock first and then the alarms.

With the button you switch to the next field PL2, PL3 with increases and decreases with PL4; when you get to the last field, pressing the button again PL2, the cycle begins again by placing the cursor on the day and so you can go on to 'infinite. At any time, pressing the button to access the menu PL1 output.

The exit menu offers the following choices: Press the button to exit without saving anything PL1, PL2 are saved by pressing the alarm settings and pressing the button PL3 you save the settings of the clock / calendar.

In line 4, the time is displayed ready for the possible setting with the aim to synchronize with another clock. For synchronization, press the button PL3 about a second before the correct time, for example if the set time is 14:00:00, press the button PL1 when the sample clock marks the hours 13:59:59.

While the clock is running, pressing the PL5 you can switch the brightness of the backlight of the LCD display from low to high and vice versa.

Setting alarms:

The watch has three alarms equal and independent. During setup you can adjust the hour and minute of the alarm, the alarm will sound when the latter are always 00. After setting the hour and minute must set the operating mode of the alarm.

The modes are:

Off = The alarm remains set as time but will not play (no symbol)
Every day = The alarm will sound every day without the need to activate it (eg every night) (symbol: a square full).
Once = The alarm clock is set to go off at a certain time after the alarm clock rings is automatically disabled and will no longer play (symbol: asterisk).
From MON to FRI = The alarm will sound at the set time every day from Monday to Friday, except on Saturdays and Sundays. (symbol: w weekends).
From MON to SAT = The alarm will sound at the set time every day from Monday to Saturday except Sunday. (symbol: d exclusion Sunday).


When an alarm is turned off, the normal operation of the watch is displayed as -: - to indicate that it is disabled in order to avoid confusion, displaying only the time of active alarms. In setting mode instead, it displays all the alarms.

When an alarm sounds, you can press the button to turn it off PL1 or PL5 press the button to activate the snooze mode.

When you activate the snooze mode (nap ...) the alarm is deactivated temporarily and will resound after 10 minutes, this cycle can go on for 10 minutes in 10 minutes. Used to wake up calmly ... or to get even a few minutes of rest. When the alarm sounds, snooze mode, to put it back into snooze mode, press the button again PL5 PL1 instead of the button that turns it off permanently. With it on, you can press the snooze button PL5 to choose to turn off the alarm permanently while in this mode without waiting for the alarm to ring again to turn it off.

In any case, when an alarm is sounding is set a timeout period that lasts 2 minutes (120 seconds) after this time the alarm goes off in the same way as pressing PL1. Do not need to sound the alarm indefinitely when there is no one to turn it off.

NOTE: Apart from the alarm sounds only once, in all other modes by pressing the button PL1 the alarm goes off but remains already set for the next day.


Transmission via serial RS232:

This watch has an optional module with the driver MAX232 through which you can send via serial RS232 and therefore receive a full calendar on any computer. The signal consists of an asterisk as a marker of initial synchronization followed by a tab, then the day, month, year, day of the week, hours, minutes and seconds. The communication protocol is set to 9600 baud, 1 start, 1 stop, no parity.

If the module is installed, the program enters the routine transmission via serial otherwise, no.


A look at the electrical system:

The core clock is made from Microchip PIC 16F877A microcontroller, a micro quite complex and rich peripherals with well-8k flash memory.

The clock / calendar chip is made from Dallas / Maxim DS1306 connected to the micro via SPI (synchronous serial interface) which provides information clock / calendar and memory ram backup lithium battery. We do not use two alarms on the chip.

The accuracy of the clock is given by the oscillator temperature compensated DS32KHZ always the Dallas / Maxim provides that the base frequency of 32.768 kHz.

The 3V lithium battery provides power backup for the DS1306 and the oscillator DS32KHZ. This battery causes the oscillator is always powered even in the absence of external voltage and provides the base frequency to the DS1306. The DS1306 contains within it 96 bytes ram always backed up with a lithium battery, which is stored alarms (hours and type of alarm).

64 Kbits of EEPROM from Microchip 25LC640 page with 32 bytes, contains information about holidays and birthdays. This memory always transfers data via SPI interface.

The base frequency for the microcontroller is 10 MHz and is generated by a temperature compensated oscillator. This clock frequency causes the micro to process a single instruction in 400ns (nanoseconds), ie about 2,500,000 instructions per second.

The LCD of the initial prototype of this project is to Crystalfontz 4 lines of 20 characters and is the model CFAH2004A. This LCD has white lettering on a blue background. The configuration used in this project is of 4 bits.
NOTE: You can use any other display 4 lines of 20 characters compatible.


The BC327 PNP transistor serves as a bypass to the second resistor (200 Ohm) to increase or decrease the brightness of the LCD backlight. It 'convenient lower the brightness in the dark to avoid being dazzled during the night.

The buzzer alarm is used for the KPE 204 (with built-in oscillator) manufactured Kingstate, this buzzer can be powered from 3V to 20V with a power consumption of about 9 mA. Sound pressure about 93bD. Acoustic frequency 3.4 kHz.

Other buzzer tried SMA24 is the model of the firm Sonitron. However, in fact okay to plug any buzzer 5V and with a consumption of not more than 20mA.


Principle of operation:

Power-up the micro sets the I / O ports, initializes the SPI interface for dialogue with the clock / calendar and configures its registers. Is displayed on the LCD copyright for about 5 seconds and then displays the clock / calendar.

The main loop of the program is to test the signal edge at 1 Hz from the DS1306 and when the state goes from zero to one, it means that the time within the DS1306 is varied so the micro DS1306 requires the new data time and calendar, and if the day has not changed, updates the time, but if the day is also changed, also updates the calendar.

During the cycle, on the edge of the signal at 1Hz, are tested PL1 buttons for activating the functions of clock setting and button PL5 for the brightness of the LCD backlight. Along with the buttons, it checks whether the second is 00, if so, the alarms are tested to see if one of the alarms should sound also is managed both as a snooze time as reactivation of the alarm.


Schema elettrico - Electric diagram




Prototipo, alimentatore - Prototype, power supply




Prototipo, interfaccia seriale - Prototype, serial interface




Prototipo, vista generale - Prototype, seen general




Prototipo, particolari - Prototype, details




LCD, versione inglese - LCD, English version




LCD, impostazione orologio e sveglie - LCD, setup clock and time to get up




Sveglia, suona tutti i giorni - Alarm, plays all of the days




Sveglia, suona una volta sola - Alarm, an alone time




Sveglia, suona dal lunedě al venerdě - Alarm, from the monday to the friday




Sveglia, suona dal lunedě al venerdě - Alarm, from the monday to the saturday




Sveglia, disabilitata - Alarm, disabled




Menů di uscita - Menu of exit




Versione italiana - Italian version




Visualizzazione festa... - Display party...




Visualizzazione festa... - Display party...




Visualizza etŕ del festeggiato... - It visualizes age of the guest of honor...




Visualizza nome del festeggiato... - It visualizes name of the guest of honor...




Menů di uscita - Menu of exit




Modulo seriale - Serial module




Modulo seriale - Serial module




Modulo seriale - Serial module




Modulo seriale - Serial module




Data sheet DS1306 DS1306.PDF (287k)
Data sheet DS32Khz DS32Khz.PDF (453k)
Data sheet 25LC640 25LC640.pdf (357k)
Using the EEPROM 25LC640 Utilizzo_EEPROM.pdf (23k)

Italian HEX file for PIC 16F877A ClockITA.zip (8k)
English HEX file for PIC 16F877A ClockENG.zip (8k)




The files. HEX and the content of these pages was released for teaching applications WITHOUT end of I make money from. For any other type of application it be able to contact me via email.

© Copyright tony@microt.it