Watch on ATmega8. Two-channel thermometer, clock on ATmega8, DS18B20, DS1307, LCD1602 Simple clock on the atmega8 microcontroller

Clock concept with big numbers

Structurally, the device will consist of two boards - one above the other. The first board is a matrix of LEDs that form the hours and minutes, the second is the power part (LED control), logic and power supply. This design will make the watch more compact (without the case, approximately 22cm x 9cm, 4-5 centimeters thick) + will make it possible to screw the matrix to another project if something goes wrong.

The power part will be built on the basis of a UL2003 driver and transistor switches. Logical - on Atmega8 and DS1307. Power supply: 220V - transformer; logic 5V (via 7805), power part - 12V (via LM2576ADJ). There will be a separate compartment for a 3V battery for autonomous power supply of the real time clock - DS1307.

I’m thinking of using Atmega8 and DS1307 (I plan to hang the clock from the ceiling, so that in case of a power outage I don’t have to fumble around for settings every time), however, the board layout will imply the possibility of operating the device without DS1307 (for the first time, and maybe forever - how it will work).

Thus, depending on the configuration, the operating algorithm of the clock program will be as follows:

Atmega8– time counter by timer. Work in a cycle without pauses: polling the keyboard, adjusting the time (if necessary), displaying 4 digits and a separator.

Atmega8+DS1307. Work in a cycle without pauses: polling the keyboard, adjusting the DS1307 time (if necessary), reading the time from the DS1307, displaying 4 digits and a separator. Or another option - reading from DS1307 on a timer, the rest in a loop (I don’t know how best yet).

The segment consists of 4 red LEDs connected in series. One digit – 7 segments with a common anode. I do not plan to separate the segments using the figure-of-eight pattern, as is done in conventional indicators.

Power part of the clock

The power part of the clock is built on a UL2003 driver and transistor switches VT1 and VT2.

UL2003 is responsible for controlling the indicator segments, the keys are for controlling the digits.

The hour and minute separator is controlled separately (signal K8).

The segments, bits and separator are controlled by the microcontroller by applying a positive potential (i.e. applying +5V) to K1-K8, Z1-Z4.

Signals to segments and bits must be supplied synchronously and with a certain frequency in order to ensure dynamic output of information (hours and minutes).

Transistor BCP52 can be used as transistor VT1 (BCP53).

Schematic of the power part of the clock with large numbers

Printed circuit board of a seven-segment indicator for a clock with large numbers

As I said earlier, the clock will consist of two printed circuit boards - an indicator board + logic and a power part.

Let's start with the design and manufacture of the indicator circuit board.

Development of a printed circuit board for a seven-segment indicator for a clock with large numbers

The printed circuit board of a seven-segment indicator for a clock with large numbers in the "lay" format is located at the end of the article, in the attached files. You can read about the technology of manufacturing printed circuit boards using the LUT method.

If you did everything correctly, the finished PCB will look something like this.

Finished printed circuit board of a seven-segment indicator for a clock with large numbers

Assembly of a seven-segment indicator

Since the indicator board is double-sided, the first thing to do is to make interlayer transitions. I do this using the legs of unnecessary parts - I thread them through the holes and solder them on both sides. When all the transitions are completed, I clean them with a flat, fine file - it turns out very neat and nice.

Interlayer vials on the indicator board

The next step, in fact, is assembling the indicator. Why do we need a pack of red (green, white, blue) LEDs. For example, I took these.

Preparing to assemble the indicator

When installing diodes, do not forget that we are making an indicator with a common anode - i.e. The "+" diodes must be connected together. Common anodes on a PCB are large pieces of copper. Be sure to pay attention to the dividing point anode.

Location of anodes on the indicator printed circuit board

As a result, after 2 hours of painstaking work you should get this:

Seven segment indicator

Digital part of the clock

We will assemble the digital part of the clock with large numbers according to the following scheme:

Clock diagram with large numbers

The clock circuit is quite transparent, so I don’t see any point in explaining how it works. The printed circuit board in *.lay format can be downloaded at the end of the article. Note that the printed circuit board is mainly designed for surface-mount parts.

So, the element base that I used:

1. Diode bridge DFA028 (any compact one for surface mounting will do);
2. Voltage regulators LM2576ADJ in D2PAK housing, 78M05 in HSOP3-P-2.30A housing;
3. Transistor switches BCP53 (SOT223 housing) and BC847 (SOT23 housing);
4. Atmega8 microcontroller (TQFP);
5. Real time clock DS1307 (SO8);
6. Power supply 14V 1.2A from some old device;
7. The remaining parts are of any type, suitable in size for installation on a printed circuit board.

Of course, if you want to use other parts packages, you will need to make some changes to the PCB.

Pay attention to the resistance values ​​R3 and R4 - they must be exactly as indicated on the diagram - no more, no less. This is done in order to provide exactly 12V at the output of the LM2576ADJ voltage regulator. If you still cannot find such resistor values, then the value of resistance R4 can be calculated using the formula:

R4=R3(12/1.23-1) or R4=8.76R3

Assembling the digital part. Version 1, without DS1307

If, when making a printed circuit board for a watch, you followed the recommendations set out in, then is it unnecessary to remind you that before assembly, the printed circuit board must be drilled, all visible short circuits on it must be eliminated, and the board must be covered with liquid rosin? Then we start assembling the watch.

I recommend starting with assembling the power supply and only then installing the digital part. This is a general recommendation for self-assembly of devices. Why? Simply because if the power supply is assembled with an error, you can burn all the low-voltage electronics that should be powered by this power supply.

If everything is done correctly, the power supply should work immediately. We check the assembly of the power supply - measure the voltage at the test points.

The figure shows the test points at which the supply voltage should be checked. If the voltage corresponds to the declared one, you can begin assembling the digital part of the watch. Otherwise, we check the installation and functionality of the power supply elements.

Test points and voltage values ​​for the clock power supply

After checking the power supply, we proceed to assembling the digital part of the clock - installing all other elements on the printed circuit board. We check for short circuits, especially in the legs of the Atmega microcontroller and the UL2003 driver.

Installation of the digital part of the clock

Please note that we are assembling the clock WITHOUT installing the DS1307 real-time clock, however, all wiring of this chip must be completed. In the future, if the need arises, this will save us time on modifying the clock for the second version, where a separate, independent real-time clock on the DS1307 will still be used.

Preliminary testing of the ATMEGA8 microcontroller

In order to check the correctness and functionality of the microcontroller, we need:

1. Programmer, for example.
2. for in-circuit programming of the microcontroller.
3. AVRDUDESHELL program.

We connect the clock board to the data cable. We connect the data cable to the programmer. Programmer for a computer on which the AVRDUDESHELL program is installed. The clock board should not be connected to a 220V power supply.

Successful reading of data from the microcontroller by the AVRDUDESHELL program

If problems arise when reading fuses, check the installation - there may be a short circuit or a “missing connection” somewhere. Another tip - perhaps the microcontroller is in low-speed programming mode, then just switch the programmer to this mode (


- alarm.
– thermometer.

1. Functions.

– indication. Alternate.

PLUSMINUS

2. Setup.

2.2. By pressing a buttonMENUSET

Group CLOC:

– minutes;

- watch;

PLUS or MINUS);

With".

Group ALAr:

OnOFF" if disabled;

Group diSP:

tc

tt

EF, Ar

P

Group LiGH:

A", in the younger ones" OnOF

L_ ".

L¯ ".

L".

2.4. By holding the buttonsPLUS/ MINUS

3. Notes.

subject .

Video of the program working t userwolf2000.

– watch with digital accuracy correction.
- alarm.
– thermometer.
– indication on a seven-segment indicator.
– automatic adjustment of indicator brightness.

1. Functions.

– clock, time display format 24-hour, hours:minutes.

– digital accuracy correction. Daily correction is possible ±25 sec. The set value of 1 hour 0 minutes 30 seconds will be added/subtracted from the current time.

- alarm. At the specified time, short double signals are heard for one minute. You can turn off the sound ahead of schedule by pressing any of the buttons. When the alarm clock is enabled, a dot is displayed in the least significant digit when the time is displayed.

– thermometer. The range of measured temperature is -55.0 ÷ 125.0 o C. If the temperature is above 99.9 or below -9.9 o C, tenths of a degree are not displayed.

– indication. Alternate.

– customizable animation of changing readings.

– use of non-volatile memory of the microcontroller to save settings when the power is turned off.

– if in the main mode you press the buttonPLUS, then the time is displayed on the indicators if you click onMINUS- temperature. When the buttons are released, the automatic change of readings resumes.

– automatic adjustment of the brightness of the indicator depending on the illumination.

2. Setup.

2.1. When the power is turned on, the clock is in main mode.

2.2. By pressing a buttonMENUenters the settings mode and selects a group of parameters to install. Within a group, the parameter to be set is selected using the buttonSET. Available for installation in turn:

Group CLOC:

– minutes;

- watch;

– seconds (reset to zero when you press the buttonsPLUS or MINUS);

– correction value. In the most significant digit the symbol " With".

Group ALAr:

– activation of the alarm clock. On the indicator "On"if the alarm is enabled, "OFF" if disabled;

– minutes when the alarm goes off;

– alarm clock time.

Group diSP:

– time of indication of the current time. In the highest digits the symbols "tc". Setting range 0÷99 sec. If set to 0, the time will not be displayed;

– temperature indication time. In the highest digits the symbols "tt". Setting range 0÷99 sec. If set to 0, the temperature will not be displayed;

– selection of animation effect. In the highest digits the symbols "EF". If set to 0, information changes will be carried out without effects, if automatic mode is selected (symbol " A"), then the effects will change one by one. If the mode is selectedr, then the effects will change randomly.

– select animation speed. In the most significant digit the symbol "P". The setting range is 0÷99. One unit corresponds to approximately 2 ms, the higher the value, the slower the animation.

Group LiGH:

– enable automatic control of the indicator brightness. In the most significant digit the symbol "A", in the younger ones" On" if automatic regulation is enabled, "OF" if the brightness is set manually;

– minimum brightness threshold for automatic mode. In the highest digits the symbols "L_ ".

– maximum brightness threshold for automatic mode. In the highest digits the symbols "L¯ ".

– brightness level in manual mode. In the highest digits the symbols "L".

2.3. The parameter being set flashes.

2.4. By holding the buttonsPLUS/ MINUSthe parameter is quickly set.

3. Notes.

1. For the minimum and maximum brightness thresholds, the setting range is 0 ÷ 99, but the program introduces restrictions: the minimum cannot be greater than or equal to the maximum and vice versa.

2. When setting the brightness parameters, the information on the indicator is displayed with the selected brightness value.

3. It is necessary to compare the speed of animation and the time of displaying information. If slow animation and short display time are selected, it may turn out that the information does not have time to be completely updated before the next shift.

A topic has been created to discuss the materials of the article.

Video of the program working t userwolf2000.

This electronic clock, built on the Atmega8 microcontroller, is equipped with an easy-to-read LED display, an alarm clock with a snooze function, and a power recovery function.

Watch specifications

  • time display format: hours, minutes;
  • alarm clock with snooze function;
  • simple control using 2 buttons;
  • Battery operation support;
  • supply voltage: 7…12V / 0.2 A;
  • dimensions of two printed circuit boards: 60×21 mm, 58×44 mm.

The schematic diagram of the clock is shown in the figure below. The clock circuit must be powered with a constant voltage in the range of 7...12V. This can be any with a current load of at least 200 mA.

A buzzer with a generator can be connected to the CON5 connector of the board, which will act as an alarm signal. Buttons are connected to terminals SA1 and SA2 of the printed circuit board, which are used to enter settings and operate the clock.

Setting the time and alarm

When you press the SA1 button, we get to the “Set1” clock menu, where we have the ability to set the current time, and another short press of the SA1 button takes us to the “Set2” alarm time setting menu.

To select and change settings, use the SA2 button. After selecting both in the time setting mode and in the alarm setting mode, the first digit will begin to flash on the display, after which you can set dozens of hours using the SA2 button.

Pressing SA1 again will cause the second digit to blink and using SA2 you can set the hour units. The next two presses of SA1 will allow you to set tens of minutes and units of minutes. When setting the hours and minutes, only one digit is always set. Pressing SA1 a fifth time returns the watch to normal operation. Also, a long period of time without pressing any buttons will terminate the installation procedures.

While the clock is running, long pressing the SA2 button turns the alarm on/off. When the alarm is activated, the start time is displayed for a few seconds. The alarm status is indicated by a dot located in the fourth digit. When the alarm is active, this indicator lights up.

After turning on the alarm, you can press any button to turn it off for about 5 minutes, and the snooze function will be activated. This fact is indicated by a flashing dot on the fourth digit of the indicator. After 5 minutes, the alarm will sound again. By pressing any button again, it can be postponed for another 5 minutes, etc.

The alarm signal is completely turned off after a long press of the SA2 key, or about a minute and a half of lack of reaction from the user.

The clock operation has been tested in Proteus:

If during operation of the watch it turns out that the watch is significantly behind or in a hurry, you can try to reduce or increase the value of capacitor C1.

(34.7 Kb, downloads: 1,923)

Watch on ATmega8.

  • 10 alarms for every day of the week.
  • Delay of the signal, if the alarm is not turned off, goes off after about 5 minutes.
  • Two alarm clocks on a separate MK leg, load on/off.
  • Two DS18B20 temperature sensors (at home and outdoors).
  • Selection of temperature display (zero blanking).
  • Timer 99 hours.
  • The brightness of the indicator is adjustable for daytime and nighttime.
  • The variable parameter smoothly changes the brightness.
  • When 220 volts are lost, battery consumption is less than 40 microamps.
  • The alarm goes off in any power mode.
  • The watch can show up to 8 modes.
  • The circuit can use indicators with a common anode or cathode.

The watch can show up to 8 modes, for which you can select one of fifteen display formats, the time it will be shown and the number of times it will be skipped.

Display formats.
0

Date, Day of the week, Hours-minutes.

1

Hours-minutes-seconds.

2

Hours and minutes.

3

Hours-minutes, Day of the week.

4

Day_of_month_day of week.

5

Day month Year.

6

Day month year day of week.

7
8

Temperature 1 sensor (house sensor).

9

Temperature 2 sensor (sensor outside).

A

Temperature 1 sensor, Hours-minutes.

b

Temperature 2 sensor, Hours-minutes.

C

Temperature 1 sensor, Temperature 2 sensor.

d

Temperature 1 sensor, Temperature 2 sensor.

E

Day of the week number month year.

F

Day month Year.

In modes where tenths of degrees are not indicated, the point determines more than 0.5 degrees.

Button F—exit mode. Choice of 3 main modes.
SET button - enters the selected mode. Next, move to the next parameter (flashing field).
PLUS button - plus/on. In SETUP mode, scroll through the main menus.
MINUS button - minus/__(off). In SETUP mode, scroll through the main menus.

All modes, except zero and timer modes, have a time termination. If there are no presses for more than 30 seconds, mode is set to zero.

CALLS mode

SETUP mode.
To write values ​​to EEPROM, you need to confirm all values ​​in the submode by pressing SET.
Example: LIGHT ->SET-> L.ooooo ->SET-> НО4ь L.2 ->SET-> LIGHT .

PORT mode.

Clock mode.

Adjusting seconds. Pressing MINUS resets the seconds to zero. If there were more than 31 seconds, then the minutes are incremented.
Next comes setting the minutes and hours.
Installed:
day, month, year and day of the week.
Clock correction. This value is added or subtracted every hour. Step 0.008 seconds. (50 values), maximum value 0.391. Calculation example: with a correction equal to zero, the clock drift is measured, for example, in 5 days the clock has run away by 3 seconds, then the correction is exactly 3/(5*24)=0.025.

Set SEE mode.

In zero mode, the clock alternately shows up to 8 modes, for which one of ten display formats and the time of its display is selected (top table).
1 mode selection.
r 5 select one of fifteen display formats.
With 03 time in seconds that the selected mode will be visible.
n 0 how many times to skip (do not show) mode. Example:
1 r0 c03n0
2 r5 c03n0
3 r4 c02n1
r0; r5; r4; r0; r5; r4; r0; r5; r4; r0; r5; r4; ..
r4; — visible, r4; - missed.
When the time is 00, the mode is disabled.

Mode USt Bud. Alarm settings.

Bip alarm signal - PWM.
Pin alarm signal - mouth in 1 output bud.
Both Shim and output.
Signal delay.
Sets the number of signal delays.
When off Snooze (00) turns off the alarm by pressing any key.
When on alarm snooze off button F, when pressing the SET PLUS MINUS buttons, the signal turns off, but will work again after about 5 minutes.
When signal delay is active, in zero mode, the dot of the last digit blinks.
Disable delay (if there is no signal). In mode 0, pressing SET on. this mode. The presence of an active delay induces the symbol O at the 4th acquaintance place. Pressing PLUS MINUS turns off the delay.

DS18B20 mode.

Light mode.

Signal mode.

Reset mode.

Actions in zero mode.

F - mode selection.
SET - signal delay cancel mode
PLUS - Set SEE mode.
MINUS - setting alarms.

Every hour, for one second, pin PB2(16) is set.

To save money, signal delay is prohibited in battery mode. The timer also stops running.

Source WinAVR-20060421. Firmware anode, cathode and firmware for a circuit with large indicators. With automatic transition to summer/winter time.
No changeover to summer/winter time.
Diagram for large indicators. Sent by Alexey.



I bring to your attention a simple diagram and design “ Two-channel thermometer, clock on ATmega8, DS18B20, DS1307, LCD (ZhK) 1602«.
The design allows you to display the current time, date, month, day of the week and current temperature from two digital temperature sensors on a two-line symbol indicator.

Diagram of a two-channel thermometer and clock

The design is assembled on an ATmega8-16PU microcontroller, a DS1307 real-time clock chip in a DIP package, DS18B20 digital temperature sensors, and an LCD1602 LCD indicator


The device diagram was created in the program
Temperature sensors are connected to connectors DS1 and DS2:
— pin 1 — to the GND pin of the sensor
— pin 2 — to the DQ pin of the sensor
— pin 3 — to the Vcc pin of the sensor

The sensor connections in the diagram do not correspond to the printed circuit board.
The program is tailored to the printed circuit board, you need to connect:
— 1st sensor to PB1 (15th pin)
— 2nd sensor to PB2 (16th pin)

I draw your attention to connecting the pins of port D of the microcontroller to the pins of the indicator:
- PD0 of the microcontroller - to pin D7 of the indicator
- PD1 of the microcontroller - to pin D6 of the indicator
- PD2 of the microcontroller - to pin D5 of the indicator
- PD3 of the microcontroller - to pin D4 of the indicator
This connection was chosen to simplify the layout of tracks on the printed circuit board

Details used in the design:

The LCD display is 2-line, 16-character negative, white characters on a dark blue background with white backlighting. You can also use any similar character-synthesizing (symbolic) two-line, 16-character indicator, with or without Cyrillic support, that supports the command system of the HD44780 type controller:
— STN (FSTN) Negative (blue or black) with backlight (this is used in the design) — such indicators only work with backlight
- FSTN Positive, TN Positive, HTN Positive - with or without backlight
The Chinese LCD indicator used does not have a built-in Cyrillic alphabet, therefore, for clarity of displaying the day of the week on the indicator, custom characters are written into the character generator RAM (CGRAM) - “P”, “n”, “t”, “Ch”, “b” and two characters in inverse form “D” and “U”.

Printed circuit board of a two-channel thermometer and clock

The design is assembled on a single-sided printed circuit board, all used parts are “output”
The device's printed circuit board was created in the program.
There are three jumpers on the board - P1, P2, P3
The quartz resonator is installed “lying” on the board; the resonator body is soldered with a jumper to the contact pad on the board under the resonator.

Description of the operation of a two-channel thermometer and clock

The basis of the design "D" two-channel thermometer, clock" is a microcontroller ATmega8 in a DIP package with a clock frequency of 1 MHz from a built-in oscillator with an internal RC circuit. The FUSE bits are set by default, no need to change anything.
A real-time clock chip is used to determine the current time DS1307, which counts seconds, minutes, hours, date of month, month, day of week and year with leap year compensation valid until 2100.
Only the following are displayed:
- current time - hours and minutes
- date of month
- month
- day of the week
Two digital temperature sensors are used as temperature sensors DS18B20, which allow you to measure the current temperature ranging from -45 degrees to +125 degrees Celsius with an accuracy of 0.5 degrees.
The current temperature of each sensor is displayed with a resolution of 0.1 °C
Before the value of each temperature, the symbols “D” and “U” are displayed in inverse form:
- “D” - temperature in the house
— “U” — outside temperature

The program's operation is organized by overflow interrupts from timer T1 occurring every 4 seconds. The current time is updated every 4 seconds, the current temperatures from the sensors are updated alternately, every 4 seconds.

The device is powered from a stabilized power source with a voltage of 5 Volts; you can use a charger from a cell phone, or an autonomous power source - a battery. The current consumption depends on the brightness of the backlight (the value of resistor R3) and in a particular case is 12 mA.

The device is controlled by two buttons:
— S1 — “Selection”
— S2 — “Installation”

When the device is turned on for the first time (or every time it is turned on in the absence of a backup power supply DS1307 - BAT1), the device goes into the “Full” installation mode. In this case, it is necessary to set the current year, month, date, day of the week and current time - hours and minutes. In this mode, the explanatory information was not translated into Russian (unlike the day of the week indication), all explanations are displayed in English (a complete installation is performed extremely rarely, it is not difficult to understand):

Setting the Year:
A blinking cursor in the form of a white rectangle indicates where and what needs to be entered:
— with the “Install” button — we set it to tens of years
- using the “Select” button - proceed to setting the year units
— using the “Setup” button — set the value of the year units
— with the “Select” button — go to the next setting

Setting the month to “Month”
- similar to setting the year

Setting the day of the month “Data”:
- similar to setting the year

Setting the day of the week “Week”:
- similar to setting the year, with - 1 - Mon, 2 - Tue, 3 - Wed, 4 - Thu, 5 - Fri, 6 - Sat, 7 - Sun

Setting the current time “Hour_Min”
For example, the current time is 17 hours 39 minutes:
— with the “Install” button — we set tens of hours — 1
— using the “Select” button — proceed to setting the hour units
— using the “Setup” button — set the hour units — 7
— with the “Select” button — go to setting tens of minutes — 4
— using the “Setup” button — set the minutes units to -0
— the seconds are already indicated on the displays as “00”
— at exactly 17 hours 40 minutes press the “Select” button and the current time 17 hours 40 minutes 00 seconds will be recorded in DS1307

In operating mode, the “Select” and “Install” buttons allow you to switch to the following modes:
Select button— time correction (in this case, only the current time “Hour_Min” is set as described above)
"Install" button- “Full” installation
To enter the desired mode, you must press the corresponding button and hold it until the display screen clears. After clearing the display, release the button and after a second we go to the selected mode.

The design was developed and tested on a breadboard; it was not assembled in hardware.
There were many comments about the device not working and the printed circuit board not matching the circuit diagram.
It was decided to recreate the device in hardware.
Below are photographs of the assembled device according to the circuit, printed circuit board and firmware published on this page.
The device started working immediately, no problems observed.
The printed circuit board is made using the LUT method. Due to an error in installing the microcircuits on the board, they had to be desoldered and rearranged (and there is a hole in the old woman), which led to damage to the printed conductors and, as a result, the appearance is not very good, jumper P2 is installed on the side of the printed conductors (did not drill holes ), the DS1 sensor is connected with a cable about 1 meter long (so that it is at a height of about 30 cm from the floor, the DS2 sensor is connected with a cable 5 meters long and brought out of the window. The connectors for connecting the sensors are taken from the coolers of old computers.

There was one problem - the RTC DS1307 did not start right away, the reason was rosin between the quartz pins. After washing the board, the clock started working.

(10.8 KiB, 1,990 hits)

(27.3 KiB, 1,471 hits)

(390.1 KiB, 1,288 hits)

(51.7 KiB, 2,476 hits)

Download from YandexDisk (additionally - datasheets in Russian)

You can order all the necessary parts for assembling a “Dual-channel thermometer, clock on ATmega8, DS18B20, Ds1307”, including a programmed microcontroller, in the website’s online store