A ticking clock with an alarm on the Atmega48 microcontroller


This alarm clock is based on a real-time clock chip, which allows them to work from a backup power source in the absence of a primary one. The set alarm time and operation mode are stored in the non-volatile memory of the microcontroller. The display mode is 24 hours. Contain simulated "ticking" Indication of time and operating modes is carried out by means of LED indicators.

Principle of operation

The basis of these watches is the DS1307 microcircuit, a real-time clock that exchanges information with the control controller via the I2C interface. Time indication is carried out through 4 7-segment indicators operating in dynamic mode. Entering and adjusting the time is carried out by 5 buttons: "+ minutes", "+ hours", "setting", "alarm" and "reset". The sound signal of the alarm clock is output through a standard piezo emitter and is a signal with a frequency of 1 kHz with second pauses.

Atmega48 was chosen as the control microcontroller because of its availability and the availability of the necessary peripherals on board (even in abundance). The DS1307 real-time clock is connected to the I2C hardware outputs of the control microcontroller. To operate the DS1307 in standalone mode (in case of power failure to the main controller), a 3V lithium backup battery is used, which will last for several years due to the low power consumption of the chip.

Consider the control program in more detail:

The program works on the principle of a flag-timer machine: all states and events are presented in the form of corresponding flags that are executed in interrupts of the corresponding timer 1s, 1ms and 263.17ms. The program uses 2 hardware timers.

The clock chip is polled and the buttons are pressed at an interval of 263.17ms. An interval of 1ms serves to generate a sound signal of a call, and 1s - to modulate it. The second interval also controls the blinking of a point in the 2nd category of the indicator, which separates hours and minutes and also serves as the formation of a “tick”.
Consider a circuit diagram of a watch.


Designations and ratings:
S4 - Increase hours
S3 - Increase minutes
S2 - Set
S1 - Turn on the alarm
S5 - Reset

R6-R10 - 10k
R1-R5 - 510ohm

Supply voltage - 5 volts.

Setup and use

Properly assembled watches do not need additional adjustment. It is only necessary to set the current time and alarm.
The current time is set as follows:
1) Use the S1 and S2 buttons to set the current time (the point between the digits does not blink)
2) Start the clock with the S3 button To
set the alarm:
1) Press S3 and make sure that the point in the 1st discharge
2) Set the time of the call with the buttons S1 and S2
3) Turn on the call with the button S4
Additional features:
Turn on the tick - hold S4 and press S2 until the characteristic sounds appear. It turns off the same way.
Display of minutes and seconds - while holding S4, press S1. If after that to press S3 there will be a reset of seconds at 00. Return - the same combination.

Appendix: Source code (in assembler) + hex for the atmega48 microcontroller + model in Proteus .

Photo and video watches

The watch is assembled in a case from under inoperative "electronics".


Also popular now: