AVR single chip controllers AT90S, ATtiny, ATmega and ATxmega DCF77 alarm clock with LCD
DCF77 alarm clock with LCD
This application of an ATmega16 provides an alarm clock with the
Standard four line and 20 column LCD white on blue background
with convenient adaption of the backlight to ambient brightness.
Three-key adjustment plus fast and convenient potentiometer
selection of date, time and alarm time without complicated
and lengthy adjustment procedure.
Synchronization of date and time with the atomic clock DCF77
in and around Germany with any commercially available receiver
module or with the high-performance DCF77 receiver described
here. DCF77 input compatible with any polarity, comprehensive
signal duration, parity and data checking for all parts of the
DCF77 time information with detailled error messages.
Exact timing with an xtal allows reliable operation even
without DCF77 and by manually adjusting date and time.
Five different xtal frequencies can be configured with only
small changes to the source code.
Can be supplied from (rechargeable) batteries or with a wall
plugin with fallback operation for net voltage failures. Four
rechargeable 1.2V batteries are sourced with a small current
to enable background charging of the fallback supply.
Wake-up with random selection from one out of eight melodies
to be played, software is prepared to allow up to seven
additional self-programmed melodies to select from.
Widely configurable assembler source code, with comprehensive
debug code for all hardware components on board.
Comprehensive documentation of the hard- and software allows
for own extensions to the freely available source code.
The alarm clock consists of the controller ATmega16 and some
The controller clock is sourced from an xtal of 3.2768 Mhz on the
XTAL1 and XTAL2 pins. See
here for other
clock options. From this clock source the device controls date and
The in-system-programming adapter ISP6 on the pins RESET, MOSI, MISO
and SCK allows to program the chip.
The four-line LCD is attached to port C with the data bus and controlled
by two portpins on port B. The 10k trim potentiometer controls the
contrast of the LCD.
The backlight on pins 15 and 16 of the LCD is driven by the operating
voltage and PWM-switched by OC2 of the controller.
To pins ADC0, ADC1 und ADC2 are attached:
a potentiometer for adjusting input numbers,
a photo transistor for measuring ambient light,
the field strength voltage from the DCF77 receiver.
The supply voltage for the AD converter on AVCC is filtered with
a 22µH coil and a ceramic capacitor of 100nF. The analog
reference voltage on AREF is blocked with a capacitor of 100nF.
The signal output of the DCF77 receiver is connected to INT0.
The polarity of the signal is irrelevant, the software works
with both (see
the signal analysis section
for details of the decoding process).
The three keys for operation are connected to portpins PB0, PB1 and
The OC1A output from timer TC1 drives via an electrolytic capacitor
the speaker, which plays melodies.
The power supply is built with a 9V transformer, two power diodes,
an electrolytic capacitor and a 5V regulator with two Tantal
capacitors. The 5V supply is fed via a Schottky diode to allow
to add a combination of four rechargeable batteries as second
supply. The rechargeable batteries are via a resistor of 3k3
loaded with a small current (3 mA when completely unloaded,
1 mA with completely loaded batteries) from the 9V source.
The controller part was mounted on a double-sided breadboard. The
16-pin connector for the LCD is mounted towards the soldering-side
and the connections are made with solderable enameled copper wire.
The six-pin ISP connection and the sixteen-pin connector can be
seen in the lower part of the picture. To the left side the supply
connector is located.
Here the mounting of the components in a plastic box can be seen.
To the right the power supply, to the left the speaker on the side
wall, below the board with the controller and a small board with
the keys and the photo transistor.
On the bottom of the box the DCF77 superhet and the four rechargeable
batteries are mounted. Because the superhet is mounted very near to
the speaker the receiver is plugged with strong stray signals in case
that music is played on the loudspeaker. When the music finalizes it
lasts a few seconds until the influence of those stray signals
diminishes and the reception of DCF77 signals is free of errors.
When putting the device into operation the fuses of the ATmega16
have to be programmed to work with the external xtal of 3.2768 MHz.
To ease debugging of the hardware, the source code has several test
modes included. Those test modes can be invoked by setting the debug
switches in the source code to 1, reassembling and burning the
generated hex code into the controller chip's flash. All debug options
are in detail described
at least one of the debug switches to 1 invokes the include source file
debug_code_en.inc, which normally
is not producing executable code.
First the LCD shall be tested because all further test steps depend
from the LCD and its correct functioning. The LCD test issues the
text shown here and does nothing else than that.
Further test modes are:
dbgAdc: displays the result of AD conversions,
dbgKey: displays the state of key inputs,
dbgSpk: sounds a 1,000 Hz tone on the speaker,
dbgDcfDur: displays the duration of signals on the DCF77 input
in milliseconds (high and low),
dbgDcfSig: displays signal errors on the DCF77 input with longer
dbgDcfBits: displays the last eight bits received via DCF77,
dbgMusic: displays diverse parameters when playing music.
With those debug switches all external hardware can be tested.
Consult the debug switches (all have to be zero for the final version)
and the adjustable constants in the main source code file to adjust
the code to your needs. Then assemble the code (either with ATMEL's
assembler 2, with gavrasm
or with the assembler simulator
avr_sim. If you do not know
how to assemble, consult the how-to for
Do not forget to change the fuses of the ATmega16 and, if your xtal
frequency is different from 3.2768 MHz, to adjust the constant
clock in the main source code, otherwise your time and date
will not be correct.
3.3 Description of the software, documentation
The functioning of the software is comprehensively described
here, all functions
are in theory and practice listed there.
Praise, error reports, scolding and spam please via the