One of the most enjoyable part of being an electronics person is creating your own gadgets and using them in daily life. In this article, we are building one of those with the help of SoloPCB design tools, a digital desk clock with temperature display feature.

Digital Desk Clock with Temperature Display

 

The brain of the circuit is a Microchip PIC18F252 microcontroller. It acquires precise time information from DS1307 real time clock via I2C interface and displays it on four digit 38 mm seven-segment display with the help of MAX7219CNG display driver. The temperature data is read by the on-chip ADC module of the microcontroller from LM335 temperature sensor which outputs 10mV per kelvin degree linearly. The temperature data is also displayed periodically.

The PIC microcontroller and the peripheral ICs mentioned above needs 5V regulated supply to operate. The step-down converter in the power section of the circuit, LM2574N-5.0, converts 12VDC input voltage to 5VDC and lets to draw 500mA without any significant heating problem.

There are two LEDs on the board indicates power and functional status and the buttons let the user adjust the time and display the temperature manually.

The Circuit and the PCB Design

The circuit and the PCB of the project are drawn in SoloPCB. SoloPCB is a very powerful tool which integrates the circuit design to the PCB design and the fabrication. You can download SoloPCB from FabsSream for free. The circuit and the PCB files of the project are provided in SoloPCB format. You can download the design files including the symbol and the footprint libraries by using the download link below.

Download Design Files

The following video demonstrates how to import the project libraries, open and synchronize the schematic and PCB files.

There are also video tutorials available in the Videos category showing how to use the SoloPCB tools.

The circuit schematic of the digital desk clock and a screenshot from its PCB can be seen below.

Digital Clock Circuit using PIC Micro Controller

3

After the PCBs fabrication, the components listed below are assembled on the board.

Bill of Materials:

Quantity Part Description Designator
1 CR2032 Battery Holder B1
1 22uF 16V Tantalum Capacitor C1
1 10uF 16V Electrolytic Capacitor C10
1 220uF 16V Electrolytic Capacitor C2
5 100nf 63V Ceramic Capacitor C3 C6 C7 C8 C9
2 22pF 50V Ceramic Capacitor C4 C5
1 MBR-150 1A 50V Schottky Diode D1
1 3mm Red LED D2
1 3mm Green LED D4
1 LM335 Temperature Sensor D3
1 BAT42 200mA 30V Schottky Diode D5
1 DC-001 Power Connector J1
1 1×5 2.54mm Male Header J2
1 2×4 2.54mm Male Header J3
1 150uH 850mA Inductor L1
4 38mm Common Anode 7 Segment Display LD1 LD2 LD3 LD4
3 330R 1/4W Resistor R1 R2 R11
6 10K 1/4W Resistor R3 R4 R5 R7 R8 R10
1 2K 1/4W Resistor R6
1 27K 1/4W Resistor R9
3 SPST-NO 6mmx3.5mm Tactile Switch SW1 SW2 SW3
1 LM2574N-5.0 0.5A Step-Down Converter U1
1 PIC18F252-I/SP Microcontroller U2
1 28 Pin DIP Socket 300mil U2 Socket
1 MAX7219CNG 8 Digit Display Driver U3
1 DS1307+ Real Time Clock U4
1 32.768KHz Crystal Y1
1 10Mhz Crystal Y2

 

All the components are through hole type so there is no need for a very good soldering skill.

4

The assembled board can be seen below.

5

The following sections explains the circuit operation in more detail.

The Power Section

We will use a 12V AC-DC power adapter to power the board. We need to convert 12VDC to 5VDC level that the ICs need and supply the required amount of current to the components. Not to deal with the heating problems, we should use a step down DC-DC converter. We choose LM2574N-5.0 fixed 5VDC step-down converter which can provide up to 500mA continuous current. LM2574 supports wide input range up to 40VDC and provides high efficiency. It requires only two capacitors, one power inductor and one Schottky diode as the external components.

It is always a secure way to assemble the power section first and test its output during the first design validation of the circuit. By this way the remaining sections won’t be affected due to any power section failure.

A 3mm LED is connected to 5VDC output of LM2775 through a current limiting resistor to indicate the power on status.

The Microcontroller Section

The circuit is built around Microchip PIC18F252 microcontroller. Mainly it communicates with the real time clock, display driver and the temperature sensor via digital I/O and analog input ports and displays the gathered information on the seven-segment displays. It also gets the pre-defined user commands such as adjusting the time and displaying the temperature via the push buttons.

There are some essential connections and external components that must be considered while building the circuit. First of all a crystal oscillator should be connected to OSC1 and OSC2 pins with 22pf ceramic capacitors coupled to ground. PIC18F252 supports up to 16MHZ input clock. To be able to function the MCU at the highest speed, we can use a 10MHZ clock and activate the Phase-Locked-Loop (PLL) module of the MCU which quadruples the clock frequency.

Another essential connection is connecting the MCLR pin to VDD, namely +5VDC in this circuit. A 10K pull up resistor is used for this connection. A pushbutton which is connected between the MCLR and the GND can be used as the reset button.

A bypass capacitor has a value of 100nF is also an essential component for the input power line of the MCU. It should be connected as close as possible between the VSS and the VDD pins. If it is not connected, the MCU will reset itself due to lack of instant current which cannot be drawn due to the inductance of the power line. Using a bypass capacitor will provide the required charge with low inductance since it is very close to the microcontroller.

The microcontroller should be programmed frequently while developing Its embedded software. It is really difficult to unmount and then mount the MCU after programming. To solve this problem, In Circuit Serial Programming method is used to program the MCU while it is mounted on the board. MCLR, VDD, VSS, PGD and PGC pins of the MCU should be extended to an ICSP connector for this purpose. But there is a trick that should be considered while doing this. Not to power the rest of the circuit while ICSP, a Schottky diode should be connected between the main supply and the VDD pin. So diode will prevent powering the whole circuit by using the programmer’s supply. You can find more information about ICSP in this document.

The Real Time Clock – DS1307

Real time clocks are integrated circuits which can provide the current date and the time information. They can precisely update the time by using the clock input which is generally 32.768 kHz. We use DS1307 RTC IC for this purpose. It communicates via I2C protocol. It can provide second, minute, hour, day of the week, month and the year information. It supports 12 and 24 hour formats.

To be able communicate via I2C, we need to connect two inputs of the PIC to the SCL and the SDA pins of DS1307. Those lines should be pulled-up to 5VDC supply via resistors which are 10K in our circuit.

One of the most important feature of DS1307 is continuing to run while the circuit power is off. Of course a backup supply is needed to power the IC in this case. A CR2032 cell is mounted by using the appropriate battery holder for this purpose and it is connected to the battery power inputs of DS1307.

The Seven Segment Display Driver

We use four 38 mm seven segment displays to show the time and the temperature. To make it easier to control the displays with the microcontroller, we use MAX7219 display driver IC which communicates via SPI interface. It can drive up to eight seven-segment common anode displays. An external resistor is used to limit the LED currents.

There is only two bypass capacitors and one current limiting resistor as the external components. The current limiting resistor is 27K to limit the each segment current to 20mA. In 37mm displays, there are two LEDs for each bar segment. But the dots have only one led inside.

The Temperature Sensor

LM335 is a zener type temperature sensor which has a variable reverse breakdown voltage depending on the temperature. The voltage that can be measured between the positive and the negative terminals is 10mV/kelvin. For example when we read 2980mV, this means 298 kelvin degrees and when we convert it, we can easily find 298-273 = 25 centigrade degrees. We use the 10 bit ADC module of the microcontroller to read this analog data, then convert it and display on the seven-segment LEDs.

9

The Embedded PIC Software

The embedded software of the project is developed in MikroC for PIC. The source code is given below for download. Please feel free to ask your questions and share your comments by using the comments field below.

Download Program/Code for Digital Desk Clock

 

Author

12 Comments

  1. Sir . Which software you used to build this c code ,mplab or something else

  2. Hi when i try to build the given code, it showing error like this

    undeclared identifier ‘Spi_Init_Advance’ in expression
    undeclared identifier ‘Soft_I2C_Config’ in expression

    any ideas on resolving this?

  3. Florin O

    Sorry for asking… Can I use instead of PIC18F252 a microcontroller from PIC16 family?

  4. Dear jojo,

    Thank you so much for this nice project. Is it possible to have seconds and date?
    Also Date/Clock to be toggled automatically every 2 minutes and manually with switch buttons?

    Much appreciated.

    Naser

  5. Scott Moody

    I have designed this to use SMD components for a special project I’m working on. It took forever to convert everything over to Eagle because all of the documentation is missing or different but I “think” I have it all worked out. The one area I need help with is the code. Is there a compiled hex for this?

  6. Jitendra Prusty

    Hi, Thank you for the code. I have complied it in MickroC pro for PIC and I am getting so much errors. These are blow..

    0 1139 Available RAM: 1515 [bytes], Available ROM: 32768 [bytes]
    0 122 Compilation Started P18F252.c
    1028 123 Compiled Successfully P18F252.c
    0 122 Compilation Started __Lib_Delays.c
    172 123 Compiled Successfully __Lib_Delays.c
    0 122 Compilation Started __Lib_MemManager.c
    34 1508 Implicit conversion of int to ptr __Lib_MemManager.c
    231 123 Compiled Successfully __Lib_MemManager.c
    0 122 Compilation Started __Lib_GlcdFonts.c
    1207 123 Compiled Successfully __Lib_GlcdFonts.c
    0 122 Compilation Started __lib_mmcfat16.h
    71 123 Compiled Successfully __Lib_MmcFat16Constants.c
    0 122 Compilation Started __Lib_TFT_Defs.c
    2121 123 Compiled Successfully __Lib_TFT_Defs.c
    0 122 Compilation Started __Lib_TFT_16bit_Defs.c
    2006 123 Compiled Successfully __Lib_TFT_16bit_Defs.c
    0 122 Compilation Started Digital clock using PIC.c
    10 380 Arguments cannot have explicit memory specificator Digital clock using PIC.c
    14 315 Invalid expression Digital clock using PIC.c
    14 300 Syntax Error: ‘)’ expected, but ‘data’ found Digital clock using PIC.c
    14 402 ; expected, but ‘)’ found Digital clock using PIC.c
    14 424 ‘}’ expected ‘;’ found Digital clock using PIC.c
    96 324 Undeclared identifier ‘Spi_Init_Advanced’ in expression Digital clock using PIC.c
    99 324 Undeclared identifier ‘Soft_I2C_Config’ in expression Digital clock using PIC.c
    0 102 Finished (with errors): 17 Sep 2015, 11:16:35 Digital clock using PIC.mcppi

  7. devenant riche

    Great website. A lot oof useful information here. I’m sending it to a few friends ans also sharing in delicious.
    And naturally, thanks for your effort!

  8. Is this available in Kit form? If yes, at what cost?

  9. Well.. I am regular reader of circuits today. I am engineering student seeking a great information for my final year project. This seems very good and simple project.