Pfad: Home => AVR overview => Applications => Digital clock
Digital clock

Digital clock with an ATmega16


This application of an AVR describes a digital clock with 7-segment clock and alarm time display with an ATmega16. The digital clock has the following properties:

0 Content

1 Hardware

1.1 Processor-Hardware

Schematic Processor

Alternative: Schematics in PDF format

The hardware consists of Additionally the power supply is displayed, with If the net power supply fails, the accumulator takes over supply. With exception of the display all other functions of the clock remain operating.

To the top of page

1.2 Display-Hardware

Scheme Display

Alternative: Scheme in PDF format

The display hardware consists of The cathodes of the four time display devices are connected. The resistors for current control are designed for an as-low-as-possible power consumption. For higher brightness of the time display 100Ω resistors can be used instead of the 220Ω's.

The cathodes of the four alarm time displays are also connected and are, through current limiting resistors, tied to the connector.

The connections of the anodes have separate lines on the connector for time and alarm displays and are connected on the driver transistors, mounted on the processor unit.

To the top of that page

2 Using the keys

When switching the clock on, the time and alarm time are both set to 00:00, and the alarm is disarmed.

In that mode, the adjustment of the time is started by clicking the red key. The colon between hour and minute display is on, the hour dsiplay follows the potentiometer value by displaying any number between 00 and 23. By pressing the black key the adjustment of the time is skipped immediately. By pressing the red key, the hour info is entered into an interim storage. Now the minute display follows the value of the potentiometer, displaying numbers between 00 and 59. The black key skips the time adjust mode, the red key takes over the minute info and adjusts the time. No the clock is running and the colon blinks in a second pulse.

Adjusting the alarm time is started with the white key, the display of the alarm time can be followed on the smaller display. By adjusting hours and then minutes and taking over the new values with the white key, the alarm is armed, the colon between hours and minutes blinks in a second pulse.

Alarm arming can be switched off and on with the black key. When armed, the colon blinks, and adjustment of time and alarm is deactivated in this mode.

If the time is equal to the armed alarm time, the alarm starts by playing the stored melody. Playing is repeated after a short time. Switching the alarm off can be achieved with the black key. By pressing the red key instead, the alarm is switched off, the alarm time is advanced by five minutes (snooze function). Repeatedly pressing the black key advances the new alarm time further. When deactivating the alarm then, the original alarm time without extra snooze incrementation is set.

To the top of page

3 Software

3.1 Software source code

The assembler software for the clock is available here in HTML format or can be downloaded as assembler source code here.

The code works as follows:
  1. Display and display modes
  2. Display multiplexing
  3. Display dim
  4. Time and alarm
  5. Keys
  6. AD conversion
  7. Alarm
To the top of that page

3.2 Programming melodies

Programming a melody goes as follows:
  1. The melody is stored as a table in the EEPROM.
  2. Each note requires two bytes storage space: the first byte codes the frequency or divider rate of TC0 in CTC mode, the second byte codes the tone duration and gives the number of timer runs, divided by 32.
  3. The table starts at address 0000 in EEPROM and ends with the combination 0,0.
  4. Because the ATmega16 provides 512 bytes EEPROM, the melody can have 255 notes (512 / 2 - 1).
  5. The coding in the source code starts with the directive "e;.eseg"e;. The playable gamut reaches from E2 (659 Hz) to C5 (4186 Hz), available as constants named "cfxx".
  6. The tone duration of the tones of that gamut are given as constants "cdxx", so encoding the tone E2 should add the two constants cfE2 and cdE2 to the table in the EEPROM.
  7. From these constants ccxx and cdxx the complete melody can be composed and with the directive "e;.db"e; a table can be generated.
  8. The hex file "e;digiclock.eep"e; that is generated during assembling the source code has to be written to the EEPROM after flashing the processor's code.


To the top of that page

3.3 Fuse adjusting

Fuse adjust Be aware that fresh ATmega16's are working with the internal RC clock. After writing the flash and EEPROM code and prior to using the clock the fuses of the ATmega16 have to be adjusted to use the external crystal as clock source. This is done at best within the clock by ISP programming.

The fuses "SUT_CKSEL" (to External Crystal/Resonator Medium Frequency"), "JTAGEN" and "EESAVE" are to be changed according to the picture.

To the top of that page

©2011 by http://www.avr-asm-tutorial.net