Electronic clock circuit on pic16f628a. Electronic clock alarm clock. Unusual design case

Tabletop and Wall Clock with thermometers are made in cases from analogue clocks. The clock and thermometer are manufactured as separate, independent devices.

I won’t describe the thermometer, it is posted on the same website, a thermometer for PIC16F628A and FYD5622FS-11. The circuit, printed circuit board and firmware are there, everything is unchanged.

The temperature sensor DS18B20 of the table clock is located outside the window. Insulated wires 0.35mm, approximately 10 meters long

The clock is assembled on single 7-segment green LED indicators. The size of the numbers is 14x25.4mm - clearly visible from any corner of the room. Please note that the indicator is connected without quenching resistors. This is because each segment consists of two LEDs connected in series and has a nominal voltage of 3.8 volts. With dynamic indication, currents do not exceed permissible values.

The voltage stabilizer is located in the plug adapter. It is assembled on a 3-watt transformer and a high-frequency converter - stabilizer LM2575T-5.0 standard scheme. The microcircuit without a heatsink practically does not heat up. Connector for 3.5mm power supply. Quartz 4 MHz.

Transistors npn any low-power ones. Buttons 6×6 H=14/10mm soldered on the conductor side . The length of the button pusher is selected based on the design requirements. Each time you press the button, a unit is added. When held, the count speeds up to a reasonable speed.

Resistors MLT – 0.25. R3 – R6 1-3 kOhm.

Batteries: 4 pieces of GP-170, or similar. When disconnected mains voltage they only power the microcontroller. It is advisable to select diodes with the lowest voltage drop in the forward direction.

The boards are made of one-sided foil fiberglass.

HEX file, diagram, seals in folder No. 1.

Option 2: on one board

This case did not fit two boards: a clock and a thermometer. I didn't want to reduce the size of the clock indicator.

Display time and temperature with one indicator in turn in table clock I don't like.

I had to take another smaller indicator for the thermometer and draw a new printed circuit board. Therefore, the circuit and firmware for the thermometer are different.

HEX file and thermometer diagram in folder No. 2. Printed circuit board in the same place.

The clock diagram without any changes is taken from the first section.


This version of the watch is made in such a way as to simplify the circuit as much as possible, reduce power consumption, and ultimately obtain a device that easily fits in your pocket. Having selected miniature batteries to power the circuit, SMD mounting and a miniature speaker (for example, from a non-working mobile phone), you can get a design slightly larger than a matchbox.
The use of a super-bright indicator allows you to reduce the current consumed by the circuit. A reduction in current consumption is also achieved in the "LoFF" mode - the indicator is off, and only the blinking dot of the low-order digit of the clock is turned on.

Indication
Adjustable brightness of the indicators allows you to choose the most comfortable display of readings (and again reduce energy consumption).
The watch has 9 display modes. Switching between modes is carried out using the “plus” and “minus” buttons. Before the readings themselves are displayed, a short hint about the name of the mode is displayed on the indicators. The duration of the hint display is one second. The use of short-term prompts made it possible to achieve good ergonomics of the watch. When switching between display modes (of which there are quite a lot for such a simple device as an ordinary watch), there is no confusion, and it is always clear which readings are displayed on the indicator.


Correction of the readings displayed on the indicator is activated by pressing the "Correction" button. In this case, a short-term prompt is displayed for 1/4 second, after which the adjusted value begins to blink at a frequency of 2 Hz. The readings are corrected using the plus and minus buttons. When you press the button for a long time, the auto-repeat mode is activated at the specified frequency. The auto-repeat frequencies for pressing a button are: for hours, months and day of the week - 4 Hz; for minutes, year and indicator brightness - 10 Hz; for the correction value - 100 Hz.
All adjusted values, except hours, minutes and seconds, are written to EEPROM and restored after turning the power off and on. The seconds during correction are reset to zero. All modes except hours-minutes, minutes-seconds and LoFF are automatically returned. If no button is pressed within 10 seconds, the clock switches to the hour-minute display mode.
By pressing the button "On/Off alarm." The alarm clock turns on/off. The activation of the alarm is confirmed by a short two-tone sound. When the alarm clock is on, the dot in the low-order digit of the indicator lights up.
In the "Corr" mode, a correction constant is displayed on the indicator, the initial value of which is 5000 microseconds per second. When the clock lags, we increase the constant by the amount of lag calculated in microseconds per second. If the clock is in a hurry, then we reduce the constant according to the same principle.

I offer two very simple circuits for self-assembly, namely a clock on a PIC and AVR microcontroller. The basis of one scheme AVR microcontroller Attiny2313, and the other PIC16F628A

These clock circuits on a microcontroller will greatly help novice radio amateurs understand the issues of operation and programming of microcontrollers.

Let's take a closer look at this simple diagram: Power can be supplied either from three AA batteries or from


The Attiny2313 microcontroller is clocked by 16 MHz quartz. As a time counter, in internal circuit The microcontroller uses a 16-bit timer with a divider by 256. As soon as the internal counter counts to 625, an interrupt occurs. Therefore, we will have interruptions 100 times per second.

The time interval is taken into account in global variables, and each interrupt requires the millisecond value to be increased by one. As soon as the number of milliseconds reaches 100, you need to increase the value of seconds by one and reset the milliseconds to zero. And so on in accordance with the same algorithm up to tens of hours, which are reset only when the value reaches 24 and without increasing the next digit.

In accordance with this principle, we create the current time value recorded in global variables. Now we need to visually display this data. Since the microcontroller has a limited number of ports, we will use such a feature as the inertia of the sa15-11gwa digital segment indicator. The cathodes of its indicators are connected in parallel, and the anodes have separate control, which allows you to display a number on any of the four indicators at any time.

By quickly switching the microcontroller port to which all the cathodes are connected and quickly switching the anodes, it creates the illusion that all four digits are displayed in the segment indicator, although in fact only one of the segments is working. If current time 11:57, then first we display the number one on the first clock indicator, after 1 ms we display the number 1 on the second indicator, after another 1 ms we display 5 on the 3rd indicator, after 1 ms we display 7 on the 4th indicator and so on cyclically, updating each indicator after 1 ms.

The state of the clock control buttons is polled at the end of each display cycle about 40 times per second.

Drawing printed circuit board executed in the program and download the firmware for the microcontroller from the link above. and directly about the intricacies of the firmware, read here.

This design, although based on a different type of microcontroller, is no less complex than the previous circuit.


The operating algorithm of the firmware is also simple; the archive contains very detailed comments on the program code. Two toggle switches kn1 and kn2 are designed to correct the time - hours and minutes. The accuracy of the watch depends on the frequency of the quartz used.

Structurally, the clock is made on two printed circuit boards located side by side at an angle of 90 degrees. The indicator is located on the first board, and all the other electronics are on the second. Backup power is provided by three batteries placed in a holder made from an old Chinese lighter with an LED. For power supply from an AC mains, any 5V and 150mA current is suitable.


The archive, which you can download from the green link, contains the layout of both printed circuit boards in the Sprint Layout program and the firmware for the PIC microcontroller with the source code of the program for MP_LAB IDE, with detailed comments.

And the program itself can also be found here

This design has digital correction of stroke accuracy, as well as a built-in thermometer, which alternates with exact time displays temperature readings on the LED display. The clock design uses a non-volatile microcontroller memory that saves settings and settings even when the external power is lost.


To control the anodes of LED indicators, transistor switches are used according to a standard switching circuit.

When you turn it on for the first time, an advertising screen appears on the display for one second. Then the time is displayed. Pressing the SET_TIME button switches the indicator in a circle from the main clock mode:

Absolutely, in all cells, holding down the PLUS/MINUS buttons performs accelerated installation. If the settings were changed by the user, then after 10 seconds the new values ​​will be stored in the non-volatile memory of the microcontroller and will be read. When flashing the MK firmware, set it as follows:


You can evaluate the external design of the device from the photographs below; the stitching and additional files for the design can be downloaded from the link just above.


Shift schedules are implemented in the alarm clock firmware: 4/5 (four on the fifth) – 4 days in 1 shift, 1 day off, 4 days in 2 shifts, 1 day off, 4 days at night, 1 day off; – day, night, 2 days off; On weekdays – Mon-Fri - working days, Sat-Sun - Closed; ( Holidays are not taken into account); Daily.

The user himself selects the type of alarm schedule and sets any alarm time. In the 4/5 and day, night, 2 weekend options, you must additionally select the current shift.

In addition, the following functions are implemented in the MK firmware: Transition to the summer-winter period; Time adjustment; Accelerating alarm signal; Displaying zero in the hour and date digits

The clock circuit is based on the DS1307 clock chip and the MEGA8 microcontroller. The circuit (placed in the archive with MK firmware and printed circuit board drawings) is designed for the use of seven-segment digital indicators with a common anode for a voltage of 5V. (ATTENTION! For simplicity, ballast resistors are not shown in the diagram. They need to be installed on each segment of indicators. There are 112 pieces in total. The nominal value is calculated according to the documentation. I used segment indicators like fys15011 and fyd-5622. If you use more powerful ones, then most likely without additional transistor switches not enough.

The printed circuit board drawing was developed for an existing box from an old broken watch. You can connect a low-power load to the Alarm connector, say a musical card, and use jumper JP1 to disconnect the internal beepper. The microcontroller can be flashed directly on the board, which greatly facilitates setup in case of modification of the design.

Setting the clock
To do this, you need to enter the parameter setting mode:
Parameter-Value-Save in memory
P.01 - CLOCK [-]
P.02 - MINUTES [-]
P.03 - DAY [-]
P.04 - MONTH [-]
P.05 - YEAR [-]
R.06 - Alarm type [+] (1-4/5; 2-5/8; 3-railway schedule; 4-daily)
P.07 - CHANGE [+]
P.08 - Bud.1.HH [+]
P.09 - Bud.1.MM [+]
P.10 - Bud.2.CHH [+]
P.11 - Bud.2.MM [+]
P.12 - Bud.3.CHH [+]
P.13 - Bud.3.MM [+]
P.14 - Adjustment (D.H) [+]
P.15 - Summer/winter period [+]
P.16 - Accelerating beeper [+]
P.17 - Display leading zero in hour digit [+]
P.18 - Display leading zero in date digit [+]

Alarm Setting: Button On/On Alarm. - On/On is carried out, in this case: With alarm type 1: Alarm 1 - 1st shift; Bud.2 - shift; Bud.3 - 3rd shift;
Shift schedule: 1,2,3,4 - first shift; 5 - day off; 6,7,8,9 - second shift; 10 - day off; 11,12,13,14 - 3rd shift; 15.16 - day off; Then the days repeat.
With the first type of alarm 2: Alarm 1 - sets the alarm time; Bud.2, Bud.3 - does not work; Shift schedule: Weekdays.
With the third type of alarm: Alarm 1 - the time of day is set; Bud.2 - sets the time at night; Bud.3 - does not work;
Shift schedule: – day, night, 2 days off;. When the alarm type is 4 Alarm 1, Alarm 2, Alarm 3, the time is set; If you plan to use only one alarm clock, set the times of three to the same time.
With shift schedule: Daily. If you press the Alarm Off buttons. in parameter setting mode, the settings will be exited without saving.
Adjustment: When making adjustments, the following method is used: +/- Ch.D, where: Ch is the number of seconds adjusted per hour (max 9). D - seconds adjusted per day. ATTENTION! No adjustments are made when the power is turned off. When you turn it on, check that the time is correct.

Clock with a small 4-digit indicator. The dot between hours and minutes flashes at a frequency of 0.5 seconds. Can be built into any object: a desk calendar, a radio, a car. Estimated error - 0.00002%. In practice, for six months there was never a need for correction.

Power supply 4.5 - 5 volts, current up to 70mA. The voltage stabilizer is located in the adapter plug. It is assembled on a 3-watt transformer and a high-frequency converter - stabilizer according to a standard circuit. For a car, of course, a transformer is not needed. The microcircuit without a heatsink practically does not heat up. Connector for 3.5mm power supply. Quartz 4 MHz. Any low-power n-p-n transistors.

Any buttons. The length of the button pusher is selected based on the design requirements. You can also solder buttons on the conductor side. Each time you press the button, a unit is added. When held, the counting speeds up to a reasonable speed.

Resistors MLT - 0.25. R7 - R14 300 - 360 Ohm. R3 - R6 1-3 kOhm. Batteries: 4 pieces of GP-170, or similar. When the mains voltage is turned off, they only supply power to the microcontroller. They hold up for 8 days exactly, I checked. Diodes with the lowest voltage drop in the forward direction. The boards are made of one-sided foil fiberglass.

Before installing the microcontroller into the panel of the manufactured board, turn on the power and measure the voltage on the 14th leg of the socket. It should be 4.5 - 4.8 volts. On the 5th leg 0 volts. If you are not sure about the quality of the manufactured board or the serviceability of the parts, check the device without a microcontroller.

This is done very simply:

  • Insert a jumper from the bare wire into the socket, terminals 1 and 14. This means that +4.5 volts from the first leg will open transistor VT 2 through a resistor and the cathode of the clock unit indicator will be connected to zero.
  • Connect any wire with one end to +, and with the other end alternately touch terminals 6,7,8,9,10,11,12,13 of the socket.
  • At the same time, observe the lighting segments and their correspondence to the diagram: + on the 6th leg - segment “g” is lit and so on.
  • Move the jumper to terminals 2 and 14 of the socket. Check all segments of the minutes unit indicator.
  • Jumper 18 and 14 - tens of hours are checked, 17 and 14 - tens of minutes.

If something doesn't work correctly, fix it. If everything is correct, program the microcontroller and insert it into the socket with the power off. HEX file is attached. Turn on the power and get a ready-made watch.

If you buy all the parts, including resistors, then according to my diagram the device will cost about 400 rubles:

  • - 22.8 UAH
  • - 10 UAH
  • FYQ 3641AS21 - 9.3 UAH
  • Panel - 3 UAH
  • Quartz - 1.5 UAH

Source: www.cxem.net


This diagram is also often viewed:

Clock on PIC16F628A and DS18B20 temperature sensor.

4 segment LED indicator.

Animated display change.

Option simple watch on the popular and affordable PIC16F628A microcontroller. In fact, the AVR project began with them.

Description of the watch.


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.

– thermometer.

– indication. Alternately.

– 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.

2. Setup.

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

2.2. By pressing a buttonSET enters the settings mode and selects a parameter to install. Available for installation in turn:

– minutes;

- watch;

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

– correction value. In the highest order the symbol "With ";

– 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 "E.F. ". If set to 0, information changes will be carried out without effects, if automatic mode is selected (symbolA ), then the effects will change alternately. If the mode is selectedr , then the effects will change randomly.

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

2.3. The parameter being set flashes.

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

3. Notes.

It is necessary to balance the speed of animation and the time it takes to display 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.

When the main power is turned off (+12V) the indication turns off, the clock continues to run. The MK is powered from a backup source.

The archive includes firmware for indicators with a common cathode and anode, a project in Proteus and a description.

Questions, wishes in the forum.

11.03.2015

Added updated firmware for an indicator with a common cathode. IN new firmware more animation effects and minor changes in the algorithm. Detailed description in the archive.



What else to read