The Binary Clock is a simple concept which displays the time in a binary format. Rather than binary coded decimal, in which each digit is displayed in binary, this clock rather makes use of a "true binary" encoding, in which the hours, minutes and seconds are displayed in binary, as a value 0 - 60. This allows us to display time using only 17 bits, rather than the 21 bits needed for BCD display. More importantly, it allows us to display the time in only 3 columns, rather than 6.
This clock also makes use of an alarm, which adds more functionality to the project. A buzzer will sound when the alarm time is reached. To deactivate alarm you need to set it up on 24:00.
The clock consists of a display built out of 18 LEDs of various colors, three tactile switches for controlling the clock functions, a real-time clock, a crystal oscillator, a simple power supply, and a buzzer. The controller itself is an ATtiny261.
Schematic | Front view | Back view | ||
The display is simple. 18 LEDs (5 red for displaying hours, 6 green for displaying minutes, and 6 yellow for displaying seconds, and one orange for indicating the alarm status (ON = activated), are arranged in a 3 column, 6 row grid. We can then ground one column with a MOSFET, and apply voltage to the rows, displaying the time for that column. This is done with each column in turn.
The tactile switches are small buttons mounted on the rear of the unit, which allow us to change the time and alarm. The central switch will either put the unit into or take the unit out of alarm set mode. When not in this mode, the two buttons on the rear of the unit will change the time stored in the RTC. When in this mode, the same buttons will change the time to which the alarm is set.
The real-time clock allows the user to unplug the clock without losing the time stored in the unit. The RTC is powered by a back-up battery when unplugged, which will maintain the time until the clock is plugged in again, at which point the RTC is powered by the power adapter. The RTC maintains time by making use of a crystal oscillator, which is also mounted on the unit.
The power adapter is a wall plug which converts 110V AC to 6V DC. A voltage regulator on the clock then reduces the voltage to 3.6 V, just above the voltage required by the ATtiny 261.
The buzzer is a simple buzzer which is sounded when necessary, predominantly when the alarm is going off.
The clock is programmed using the assembly language. The clock is set to run at .5 MHz, which is sufficient to maintain the program. The time is updated every second by the INT11 interrupt, generated by the RTC each second. First, seconds are incremented. If seconds reaches 60, minutes are incremented. If minutes reaches 60, hours are incremented. Each value is rolled over if it reaches its maximum value (hours are displayed in a 24-hour format).
If the clock is in alarm set mode, the alarm time will be displayed, rather than the clock time. Because the data is stored in opposite order in either case, the bits must be reversed before displaying. In each case, the formatted bits are loaded into a register designated for display time. The display code segment then executes, displaying whatever value exists in the display register.
The communication with the RTC is configured to I2C interfacing, and the time is communicated via Binary Coded Decimal. As such, the MCU must convert the value stored in the time register to BCD before communicating. This is done via the procedure bin2BCD. However, because the clock updates its stored time with that stored in the RTC, a second BCD2bin procedure is required, in order to translate the time received into binary notation.
The remainder of the code is used for initializing, buttons debouncing, and implementation of the I2C interface routines.
Last modified:Mon, Jan 23, 2023.