Clock with LCD and PIC 18F4620 v. 2.02


Summary characteristics


Wiring diagram version 2.02 (21/07/2012)

This version implements the anti black-out and automatic daylight saving summer / winter. Some hints on the circuit anti black-out.
The purpose is to feed the clock correctly, inform the micro is in progress a blackout and have a backup battery that allows the clock to operate alarms in the event of a blackout.
We came to this conclusion:

12Vdc power supply is required, and because not all power supplies have a good filter, we have included C1 1000uF capacitor with its anti-transient from 0.1 uF better if disc (ceramic) or polyester.

The 7809 positive regulator, stabilizes the voltage to 9V, but because of the diode D1 this voltage rises to 9.5 ~ 9.7 V for two reasons, the first is used to operate the '"or" between D2 and D3, as in presence of the mains voltage, the voltage from D2 is higher than that from D3, according because it allows us to recharge the 9V battery.

For which the diodes D2 and D3 serve as switches to determine which power source will power the 7805. Output from 7805 was added an electrolytic capacitor 470uF 16V with his against transients, with the aim to have an excellent voltage (+5 V) well stabilized.

Diodes SB140 Vishay products are of the type Schottky, fast recovery and insertion loss of about 0.45 V ~ 0.7 V compared to 0.6 silicon diode like the 1N4004.

The recommended battery is produced by Ansmann and is 250 or 300mA / h, since the battery is connected to the circuit permanently, we set the charge current to approximately 10mA.

For which the value of Rx is 82 Ohm 1/2W

(Voltage on negative D4 - Voltage drop diode - Battery voltage) / Rx

(9,7V-0,45V-8,4V)/82 = 0,85/82 = 10mA

Finally, the signal from the positive part of DZ1 from 5.1 V serves to inform the micro that we have passed from the mains (inexhaustible) on backup battery power due to a power outage. To do this is connected the input of the micro RE1 to a 5.1 V zener diode (and its resistance to fall to 220 ohms) to the negative of the diode that protects the power supply network. The zener becomes necessary because the digital input does not support an input voltage higher than 5V.

During the blackout all the buttons are locked except PL1 and PL5 for the management of alarms and snooze.

At every second, while the micro performs other functions, is also tested for the presence of the supply voltage, if this is not present, we are in the process of black-out and operating in battery is necessary to limit the consumption, for which a flag goes from zero to one, it disables the PWM that drives the LCD backlight and LED syncro 1Hz instead of flashing every second, flashes every 5 seconds to indicate that we are in the process of blackouts. Many even in the absence of the LCD backlight reflect the characters so if you are in daylight or bright room you can read the time.

The flag above, if <> 0 means that we are being backed up, is incremented every second and is worth 5 when you turn on the LED 1Hz and is reset to 1 for a new cycle.

Upon the return of the mains voltage, the PWM is reactivated and the normal cycle.

Prototype supply anti black-out as the external clock is mounted on the PCB for version 2.0

Particular adapter and 9V battery ni/mh

Prototype PCB

Render of the prototype (Do not look at the initials of the components)

Analysis function daylight saving time

Daylight saving time starts on the last Sunday in March at 2.00am, so when they get the program jumps from 2.00 hours to 3.00 hours that you add one hour going from GMT +1 to GMT +2. (You sleep one hour less)

Daylight saving time ends on the last Sunday in October at 3.00am so when they get 3.00 hours to return at 2:00 am that is repeated time going from GMT +2 GMT +1. (You can sleep an extra hour)

This feature is quite delicate because it involves more issues such as:

If an alarm clock, the last Sunday of March is set as the time in the range between the hours of 2:00 and 2:59 during the time change will never sound.

All European countries have the same time zone? (England GMT = 0 Italy GMT +1)

But ... the last Sunday in October at 3:00 am, will go back by one hour to which the clock is reset to 2.00 after 60 minutes that recur again 3:00 the night ... will return again back an hour?

These and other problems have led to decisions which are as follows, and determine the operation of the automatic change of summer and summer to winter and vice versa.


The clock automatically changes the set time regardless of the time zone for daylight saving time does not have direct relation to the time zone.

A function checks whether the current month is March or October, if so, check if the day is the last Sunday of the month with the criterion that the day must be> = 25, if the day is correct, it is verified that both on Sunday, if it is correct if it occurs in March, hours are 2:00, if so, the time is incremented by 1 and goes to 3.00. The same is true for the month of October, making sure they are the hours of 3.00, the first time that the clock shows the hours 3:00 AM to 2:00 sets a flag that indicates the same function that the time has already been changed, so the second once you recur 3:00 there will be no change.

Known issues:

  • DO NOT set alarms at the turn of the time change, if it were necessary to control the clock and reset it if necessary.

Those who have already made ​​earlier versions for free download the firmware and make the above changes:

HEX file for PIC 18F4620 Italian version 2.02 of 21/07/2012 Clock18F v2.02.rar (15k)

Datasheet battery Ansmann 9V ni/mh Ansmann Batteria 9V.pdf (83k)

Datasheet diode SB140 SB140 Vishay.pdf (78k)

Datasheet buzzer Sonitron Buzzer SMA.pdf (1,7Mb)

Datasheet buttons for pcb Pulsanti.pdf (300k)

Datasheet DS32KHz Dallas DS32kHz.pdf (400k)

Datasheet DS1306 Dallas DS1306.pdf (320k)

Datasheet 25LC640A Microchip 25LC640A.pdf (511k)

Datasheet display LCD white on black LCD 204A Series.pdf (519k)

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.