Clock on an AVR microcontroller with DS1307. Binary clock

It has been going on for many centuries. During this time, inventive people came up with all kinds of determination methods - from those depending on the position of the Sun in the sky to electronic ones. The latest fashion at the moment- this is a binary clock, completely unusual at first glance. So what is it and how can you tell what time it is by the dots that light up? Let's take a closer look at this interesting new product.

What is a binary clock?

The popularity of these chronometers is growing at an extraordinary rate. However, why be surprised, you just have to look at this new product. Original appearance, stylish design, an unusual operating principle - all this allows people with an unconventional vision of the world to stand out from the crowd.

On its screen, unlike mechanical or electronic ones, binary watches do not have hands and numbers, but multi-colored luminous dots (which flash in some models).

The whole unusual principle of their operation lies in the fact that instead of the usual decimal time, time is indicated here in which all numbers are written only using zeros and ones. This is exactly how all computer technology works, because programmers and those who are closely associated with information technology, there should be no difficulties with recalculation.

How did they appear?

The first time binary clocks were published was in 2008. It was then that Anelace presented its innovative development to the whole world. However, the emergence of stylish wristwatches with an LED screen was preceded by years of improvements, trial and error.

The prototype models of binary clocks, created at the beginning of the 20th century, were huge machines with vacuum tubes (as, indeed, the first computers). At that time they were of almost no practical interest to humans.

With the development of technology, more and more widespread received LEDs, and in the design of binary clocks they took the place of conventional lamps.

Years passed, and one person became interested in the unusual system Japanese professor medicine. His patients were elderly people with memory problems and brain activity. The professor also included binary clocks as a developmental puzzle in his rehabilitation classes. The result was simply stunning!

Why such difficulties?

The first question that arises when looking at binary clock: how to use them? At first like this in a strange way may seem like a stupid fad that will only appeal to either completely technology-minded freaks or geniuses. Usually, a watch is needed to just glance at it and find out the time, but with binary chronometers such a trick will not work. You might even be late for a meeting while you're trying to take their readings.

And yet, once you discard all prejudices, it becomes clear: this thing is extremely useful, primarily for training and developing the mind. To get used to binary clocks, you need much less time than it seems at first glance, and the variety of types will not let you relax.

Advantages

What benefits do binary watches bring to their owner compared to regular ones? Well, for starters, this is an excellent opportunity to be known as a very smart and original person in front of all your acquaintances (and just passers-by). Especially if in response to their questions you don’t clarify anything, but act mysteriously in the style of “you mere mortals can’t understand.”

But seriously speaking, a binary clock is several useful gadgets in one.

  1. Watch. Naturally, you can use them to tell the time, otherwise what kind of watch is it?
  2. Puzzle game. Allows you to have fun at any time you want. In addition, different models of such watches are based on slightly different number systems, which makes them even more interesting.
  3. This gadget is especially useful for the prevention of senile mental disabilities, but it will also be an excellent brain trainer for young people.
  4. Ultra-fashionable and modern decoration with innovative design. And yes, this watch glows in the dark.

Settings

A binary wristwatch has neither a dial nor hands in its mechanism. Instead, all time and information is displayed on the LED screen using LEDs. Because of this, the user is faced with a pressing question: how to set up a binary clock?

The coding system may vary depending on different models binary clocks, however there are some basic points to keep in mind. Typically, such chronometers have 1 or 2 modes: time and, less often, date, switched by a button. To set the desired value, most often you first need to press the Set button. Flashing lights will show that you are doing everything correctly. The Select button allows you to switch from setting hours to minutes and seconds, and from month to day.

In order to correctly set the required values ​​on the clock, it is worth mastering the basic principle of the binary number system. The “weight” of each digit can be determined by multiplying the previous one by 2. We get the following series: 1, 2, 4, 8, 16, 32. For example, in order to convert the number 110101 into the form we are familiar with, we need to add up the “weight” of each of the significant digits. We get 32 ​​+ 16 + 0 + 4 + 0 + 1 = 53.

Since different companies produce slightly different binary clocks, the instructions for them will help you understand everything in more detail.

What are the types of binary clocks?

Like most electronic gadgets, binary watches are the domain of the Japanese and Chinese. Now they are produced by many companies, the models vary in quality, but all of them can be divided into several groups according to the type of information displayed.

  • Chronometers with two rows of LEDs. One row shows hours, the second - minutes. In addition, the screen has 2 time of day indicators (AM and PM).
  • Clock with LEDs arranged in 6 rows (2 each for hours, minutes and seconds). Show time in HH:MM:SS format. To find out the time from them, you need to write down the readings of each column in the order provided by this format.

  • The watch screen can resemble a speedometer with two circles: the outer circle that shows the hour, and the inner circle that determines the minutes.
  • Some watches have 2 tracks - on the right (hours) and on the left (minutes).

There are also more sophisticated options for binary clocks. Which one to choose depends only on your desire and financial capabilities.

Almost everyone has a watch, and it is one of those things that no one can do without. to modern man. Of course, there are those who prefer to look at the clock on their phone, or at the system time of the computer, but without a wristwatch, everyone feels discomfort, every time out of habit looking at their hand. Sometimes it seems that they can’t come up with anything else, what else can they do with watches in order to make them original and truly unusual. One of the successful solutions on this path, undoubtedly, are the ones on the dials of which funny pictures are depicted, and the time can only be determined approximately - intuition and the emotional side work here. But I would also like the watch to provide food for the mind. Is this possible? It turns out that it is more than possible! Just for those who want to find daily training for the mind in a watch, or simply to surprise others with their non-standard watches, the so-called binary clock.

What is it? In fact, a binary clock is a clock where the way of presenting information is radically changed - not in the numbers we are used to, but in binary code. Although, of course, there are many binary clocks with numbers, the time is displayed completely differently than in a regular clock. In binary systems, LEDs are used to indicate time, which is why they are also called diode clock. At first, it is not easy to determine the time on such watches - either columns of numbers, or simply luminous dots located in a strange order on the dial. However, once you get the hang of it, you can easily read the time using this watch. But the uninitiated will not be able to do this! There is a certain pleasure in this - to have a stylish watch and somewhat unique knowledge.

Here, for example, is one of the easiest to understand, and at the same time, extremely stylish binary watches.

Black Rock

Where to buy: inter-time.ru
Price: 1850 rubles

At first glance, their dial evokes associations with the film "Matrix", however, this is just a first impression. Four vertical columns of numbers from 0 to 9 display: the left two are hours, and the right pair are minutes. Thus, time is read from right to left. In the photo, as is easy to determine, the clock shows 5:27. Additional icons at the top reflect all the other information: the sun corresponds to the day and date display, and the dollar signifies that the display shows the year. The glass serves as an indicator of the onset of the second half of the day. To see the time, simply press a button. This saves battery energy.

But in these binary clocks there are no numbers - you need to count the luminous points in the columns yourself.

Fashion Star

Where to buy: inter-time.ru
Price: 1600 rubles

Although at first this watch is more like some kind of equalizer, then you can get used to it and quickly determine the time.

There may not be very many luminous points. For example, if each of them is responsible for its own group of numbers.

Futurama

Where to buy: inter-time.ru
Price: 1700 rubles

The indicators can be placed anywhere on the dial. For example - arcs. Effective and convenient.

Flash Metal

Where to buy: inter-time.ru
Price: 1600 rubles

The imagination of binary watch designers knows no bounds – this watch features the silhouette of the most popular Disney character.

Mickey Style

Where to buy: inter-time.ru
Price: 1200 rubles

Here is one of the brightest and most functional binary LED clocks on the market today. The original and at the same time clear display of information makes them very convenient for everyday use.

Delta V2

Where to buy: leddirect.ru
Price: 1700 rubles

By the way, this store has many very interesting binary clocks that will appeal to the most discerning connoisseurs of binary time.

Well, those who have achieved true mastery in determining time using binary clocks will be especially interested in the watch

Where to buy: inter-time.ru
Price: 1550 rubles

For the “uninitiated” it will be very difficult to understand what time such a watch shows. There is an excellent and clear transcript for this.

Determining time from them, knowing this simple principle, is not at all difficult.

And watches with a mirrored display surface, under which there is a grid with 27 diodes, look especially impressive.

Where to buy: inter-time.ru
Price: 1400 rubles

Hours are counted along vertical lines, minutes along horizontal lines.

These, and many other binary watches, will help you look at time differently, will contribute to the development of memory, and will become perhaps the most stylish detail of your image. Those around you will be amazed not only by the appearance of such a watch, but also by how easily you can determine the time from it.

Perhaps someone else remembers what the control panels of the first electronic computers (computers) looked like. Today they can only be seen in archival photographs. Long rows of light bulbs that flickered at first glance chaotically fascinated electronics enthusiasts of those years.

The design of the binary clock presented in this article will help recreate the atmosphere of previous years.

The schematic diagram of a simple binary clock is shown in Figure 1. The circuit is based on the ATmega48 microcontroller. There is no external real-time module (RTC) in the clock circuit, which in turn slightly reduces the cost of the device.

At possible failure power supply from an external source, time counting is supported by built-in CR2032 batteries, while the LEDs are turned off. To detect the supply voltage from an external power supply, a circuit with transistor VT1 (BC847) is used.

If there is voltage at the terminals of the power connector, then it passes through diode D1, as a result of which the transistor enters a saturation state, and a logical zero is applied to the PC0 input of the microcontroller, which starts the operation of the LEDs.

Indication of the current time (hours, minutes and seconds) is implemented using three lines of LEDs. LEDs are controlled by multiplexing, which reduces power consumption and reduces the number of microcontroller pins used.

Viewing is carried out only in 24 hour format. To display the number of minutes and seconds, 6 LEDs are needed, and for the hour, 5 LEDs are needed.

The ATmega48V-10AU microcontroller is capable of operating at reduced power levels down to 1.8V, which is a big advantage. In addition, ATmega48V-10AU consumes less current. The clock signal frequency is stabilized by a 4 MHz quartz resonator, which also serves as a standard for timing.

Setting the current time (hours and minutes) is done using the SW2 and SW1 buttons, respectively. The seconds counter is reset when you press any of the buttons.

It's worth noting that these buttons are inactive when running on battery backup to prevent the possibility of inadvertently changing the time. The clock is assembled on a single-sided printed circuit board measuring 103mm×67mm.

When programming the microcontroller, it is necessary to set the microcontroller to operate from an external 4 MHz quartz resonator and disable the division of the clock frequency by 8 (this bit is called CKDIV8).

After correct assembly, the clock starts working immediately and should show 00:00:00.

The circuit is powered from a power source with a voltage of +5 V. Backup power - a CR2032 battery is not required, it only supports time counting after a power failure.

The current consumption from the battery is about 1.5 mA. With a battery capacity of about 200 mAh, it should be enough for 5 or more days of operation of the microcontroller, which is sufficient in typical situations.

As already mentioned, time is displayed in the binary system. The most significant bits are located on the left, and the least significant bits on the right. The watch is deliberately not marked with hours, minutes and seconds, so that it would be difficult for uninitiated people to guess the operating principle of the watch.

Score 1 Score 2 Score 3 Score 4 Score 5

Idea

It all started with the desire to make some completely finished device on the AVR microcontroller. The choice fell on binary clocks, because They are easy to make and look quite impressive. And also because I always liked the binary clock plasmoid from KDE which looks like this:

What is a binary clock?

For those who do not know what a binary clock is and how to determine time from it, I will make a small digression. A binary clock is simply a clock that shows time in the binary (or binary) number system, instead of the decimal number system we are used to.

Binary clocks are different (as in general, ordinary clocks) - with different quantities and the location of the indicators, with or without seconds, with a 24 or 12 hour time format, etc. I decided to go with the option that is as similar as possible to the above-mentioned plasmoid from KDE:

The clock consists of six vertical columns - two columns for hours, two for minutes, and two for seconds (from left to right). Each column essentially represents one digit (i.e., two digits for hours, minutes, and seconds).

The clock has four horizontal lines, since we need to be able to show the numbers from zero to nine (at least for the least significant digit), and the binary representation of nine - 1001, contains four digits (bits). The least significant digit is at the bottom.

The easiest way to understand what time the clock shows is by analyzing the “dial” from left to right, from bottom to top. Let's write down the value binary number represented by the leftmost column of the clock shown in the picture above (assuming that a lit indicator means one, and an extinguished one means zero): 0010 in the binary number system is 2 in the decimal number system. In a similar way, we write the value of the second column: 0001 in the binary number system (as in the decimal number system), or simply one. That is, the clock says 21 o'clock. In the same way, you can read that the clock shows 35 minutes and 28 seconds. With a little practice, you will be able to read time from a binary clock almost as quickly as from a regular one.

Implementation

So, the idea is clear, let's proceed to implementation.

Let's start with the indicator ("dial") - which is a lattice of LEDs.
Since the clock has 4 horizontal and 6 vertical rows, total quantity required LEDs - 6 * 4 = 24. In fact, you can get by with fewer LEDs, because not all digits will be used - for example, the most significant digit of the clock (the leftmost column) can show a number of no more than two (with a twenty-hour time format), which means you can save as many as two LEDs. But I didn’t do this and installed all 24 LEDs, because... wanted (in the future) to use this watch to show simple text messages.

You will need buttons to set the time. There are three of them: the first button switches the watch to time setting mode and back. The second button, digit selection, switches the column in which the time is currently being adjusted. And finally, the third increases the time in the selected column by one.

ATMega32 is used as a microcontroller. Of course, it's not necessary to use such a powerful microcontroller for such a simple task, but I already had one on hand, so I used it.

Schematic and PCB

The circuit is quite standard: microcontroller, power supply, reset, connector for connecting a programmer. A clock quartz is connected to TOSC1 and TOSC2 from which the clock will tick. The time setting buttons are connected to the supply voltage. Ten LED outputs (6 columns + 4 rows). A resistor is connected to each horizontal row to limit the current through the LED.

The printed circuit board turned out to be one-sided, but still with two jumpers on the other side (marked in red), which are quite simple to make from thin copper wire.

Frame

This is probably the most uninteresting part. But at the same time, it was she who took up most of the time.

The body itself is made of wooden boards fastened with nails and glue. After assembly, the boards were carefully sanded, covered with stain and several layers of furniture varnish.

The LEDs are installed in a grid with partitions, made from wooden rulers using a jigsaw. A piece of ordinary tracing paper (which is used for drawings or patterns) is inserted into each cell with an LED to diffuse the light.

Double-sided frosted glass is glued to the front of the watch. back part It is closed by a lid with screws, from which the time setting buttons protrude.

Software part

I decided to write the program in assembler. Not because it's the most convenient language development, but solely for educational purposes. Source codes can be found in the archive below.

I won’t describe the entire code, because... it is commented in sufficient detail. I will describe only the key points.

The scan is done in columns, that is, first the LEDs of only the first column are lit for a while, then the second, etc. This happens very quickly and the eye does not have time to notice it, so it seems that all the lit LEDs are on at the same time. To display the time value in a column, use a macro DISPLAY_COLUMN. Columns are switched using the Timer0 timer.

The time change occurs once per second when Timer/Counter2 is interrupted. Since the crystal frequency is 32768 Hz and the timer prescaler is set to 128, the one-byte timer will overflow once per second (32768 / (128 * 256) = 1) , which is very convenient.

Button clicks are processed in procedures button_stop_pressed for the button for switching the clock to setting mode and back, button_set_pressed for the time setting button and button_switch_pressed for the column switch button. Please note that in the procedure button_stop_pressed the current time is stored in the EEPROM. This is done so that the time is not reset if it is necessary, for example, to switch the clock to another socket (when the clock is turned on, the time is read from the EEPROM).

Class="eliadunit">

All the main “work”, such as polling the state of buttons, switching the active scan column and displaying the time, occurs in main. The initial initialization is done in reset.

Result

The result can be seen in the video below. Some stages of the manufacturing process are also captured there.

However, before that, learn, because, you see, it will be awkward to admit ignorance when you are asked to tell what time it is. You will tell me, of course, but your information can be compared with the readings of a traditional watch. Agree, it will be awkward. So follow simple instructions and you will learn determine time using binary clocks. There are two ways to do this.

BCD mode

Decoding

First, take a close look at binary clock. The clock display has three columns, each of which has two rows of lights.

The first column shows the hours, the second, respectively, the minutes, and the third will tell you how many seconds have elapsed. All columns have the same structure.

The first row of lights in the column reflecting the hours shows the first digit, tens, and the second, second digit, units. Each row contains from two to four lights, each of which implies a power of two. So the lowest light represents 2 to the power of “0”. This value is taken as one.

The second light represents 2 to the power of 1, which is taken as two.

The third light symbolizes 2 to the power of “2”, i.e. stands for four. Well, the fourth light displays 2 to the third power, which stands for eight (see image).

Now that you have an idea of ​​how a binary clock works, try to determine how many hours the binary clock shows in an image. You see that in the first row of the column reflecting the hours, one light is on. We remember that the first light displays 2 to the power of “0” and is read as one. Further in the second column, not a single light is lit, so it is read as zero. Based on the data obtained, we can conclude that the clock in the image shows ten o'clock. Just remember that the clock displays the time in day mode, so if you are uncomfortable, subtract twelve when the clock shows thirteen hours or more. For example, if the clock shows fifteen, then you can safely assume that it is three o’clock.

In the same way, try to determine how many minutes the binary clock shows in the presented image. So in the first row of the column reflecting minutes, you see that two lights are on. Remembering the rules for determining time using binary clocks, we can conclude that the first column displays a triple. In the second row of this column you can see that three lights are on. Remembering the powers of two, we add up all the indicators and get the number seven (see image). Comparing the first and second digits, we can conclude that the minute column shows the value 37. Let's remember the clock indicator and we get that the clock shows the time 10:37.

Decoding the indicators of seconds sometimes seems quite difficult, because seconds are constantly changing their values. You will learn to determine the value of the column with seconds when the determination of binary clock indicators reaches automaticity. So, in the presented image you see that in the first row of the column reflecting the second values, the upper third light is on. Remembering the powers of two, we can conclude that this light indicates the number 4. In the second row of the same column, the fourth light and the first one are lit, i.e. the lowest one. Following the rules for determining time using binary clocks, we can conclude that the top light means the number 8, and the bottom one, respectively, one. We add both numbers and get nine.

Result

Now we compare the value of the first and second rows of the column and get the value 49. Thus, the clock in the image shows the time 10:37:49.

True binary (binary) mode.

Decoding indicators

The method of deciphering binary clocks, which have only two rows, is exactly the same as in binary decimal mode. However, there is one caveat: now there is only one line in each row. The lights in the top column correspond to the principle of powers of two: 1, 2, 4, 8. But in the bottom column you can notice not four lights, but six. Don’t be alarmed, because the principle is followed in the second column, just a few values ​​have been added: 1, 2, 4, 8, 16, 32. There is no need to add more than six lights, because the next value will be 59, which can be written so that it will be lit first, second, fourth, fifth and sixth lights.

Determine hours

Now try to determine how many hours the clock in the image shows. You see that the first and second lights are on. Knowing about powers of two in binary clocks, we can determine that the first light means the number one, and the second, respectively, two. Let's add both indicators and get the number “3”.

In the image shown, the clock has two rows of lights, but you should remember that there can also be clocks with columns. The principle of determining time using such a clock will be the same as in this case. The main thing to remember is the binary number system, which implies only two digits for encryption, “0” and “1”. So the indicators you just defined will look like 0011 in binary, which will also be equal to the value “3”.

Determine minutes

Using the technique described, you can see from the clock in the image that the first, fourth and fifth lights are burning. In the binary system it will look like 011001. Remembering the powers of two, we can conclude that the first light shows “1”, the fourth “8”, and the fifth, respectively, “16”. Let's add up all the indicators and get the value “25”.

Determine seconds

All that remains is to determine the seconds. Do it yourself according to the described principle if your watch has a column or row displaying seconds. It is absent from the presented image, so it makes no sense to describe its definition.

Remember to practice and train your brain. Over time, you will learn to quickly and easily determine time using a binary clock, even if at first glance it seemed very difficult to you. Don't get hung up on the math, just remember the meaning and location of each light. To quickly learn how to tell time using a binary clock, buy your first watch with a column displaying seconds. The values ​​​​in it will be the largest, so, having learned to quickly determine the seconds, reading minutes and hours will become very simple for you.