Advanced Design of Smart Digital Application Using PIC 16F887A Microcontroller and DS 1307 RTC

: In an elegant phenomenon of the world, mechanical applications are replaced by electronic appliance. Especially digital clocks are smart application due to precisely time display and several types of reasons such as much reliable, free maintenance, portable, elegant outlook, inexpensiveness, tiny size and result accuracyy. Every electronics based modern real life application in any filed is now integrated with the digital calendar to enable the user to keep time and date anywhere at any time. It is often incorporated into all kinds of devices such as transports, traffic signal, radios, televisions, standard ovens, computers, laptop, cell phones and wireless peripheral to intellect the device in the way that would be easily enticed by human mind. Regarding the demand of digital clock, this paper presents graceful design of smart digital clock in a particular way that would not only be able to display time, it has an ability to display day of a week with real time. This research shows an embedded system which is constructed through PIC 16F877A


Introduction
To measure time, something is needed that will repeat at regular intervals. The number of intervals counted gives a quantitative measurement of the duration. The earliest references for the measurement of the time are the moon and sun [1]. When the sun and the moon are not visible, it is impossible to know the exact time. However clocks are developed to measure out the time in absence of the sun and the moon. The process of measuring time has progressively become more accurate, and the devices more localized eternally [2]. In this work a smart digital clock is developed which is not only shows the time operation with am-pm but also indicates the day of a week. The whole controlling operation is maintained by a PIC 16F877A microcontroller which can set timing condition of DS1307 RTC and read data from the RTC to represent time on 7-segment display. Moreover PIC 16F877A microcontroller indicates a day of a week and am/pm operation with help of decoder 74LS138 IC and LED respectively.

Objective
The goal of this study is to build up a smart application through PIC 16F887A microcontroller and DS 1307 RTC. The tricky embedded system is also comprised 7-segment display. This application especially covers maximum possible arena where it applicable. This study is also significant because of to write code segment with "Mikro C Pro" for PIC microcontroller. It is also study and learning base phenomena for an amateur who would eager to learn microcontroller, Mikro C Pro, embedded system, advanced interfacing etc.

Literature Review
The first public clock that struck the hours was made and exerted in Milan in 1335 [3]. The oldest servicing clock in England is that at Salisbury Cathedral, which dates from 1386. About 1500 Peter Henlin, a German locksmith, began to make small clock driven by a spring [4]. The first electronic clock is quartz clock. It is made with a piece of quartz like liquid crystals which eventually composed watch displays [5]. Quartz vibrates equally at thousands of times a second when subjected to an electrical current. Electronic clock at those vibrations divides then down to minute, second and fraction of seconds to show time on the dial or display. Quartz clocks provide more accurate than any mechanical time keeper [6].
However Digital clocks display a numeric representation of a time. Two numeric display formats are commonly used on digital clock such as 24 hours and 12 hours notation. Electronic clocks have predominately replaced the mechanical clocks as they are much reliable, accurate, maintenance free, portable and cost effective [3][4][5]. The modern version of electronic clock is a name of digital clock that displays the time digitally. Microcontroller like PIC 16F877A, Real Time Clock like DS1307 RTC, 7 Segments Display, LED indicators and some digital IC like 74LS138 Decoder are conventionally used to design smart digital clock [6][7][8].
There are also clocks for the blind that have display that can be read by using the sense of touch. Some of these are similar to normal analog displays, but are constructed so the hands can be felt without damaging them. Though all clocks measure time, but different clocks can have different status or importance [5,9,10]. In 2008, "Pan Thu Tun" has designed a digital clock using microcontroller with 7-segment display [11]. It simply handles the timing functions electronically rather than mechanically.

Proposed Model and Design Principle
This embedded system is constructed using PIC 16F877A microcontroller, DS1307 RTC and 74LS138 decoder IC. The proposed basic model of smart digital clock is portrayed in figure 1. The PIC 16F877A microcontroller is a heart of this clock. The microcontroller sets initial time on DS1307 RTC according to input switching conditions. After that the microcontroller reads data from DS1307 RTC and displays time on 7-segment display with am/pm mode by LED indication and also displays day by 74LS138 decoder IC indication. When designed embedded system is connected with power supply, it executes the sequential operations according to programming instructions. The flowchart of the proposed model is depicted in figure  2. First of all; microcontroller cheeks the initial condition of adjustment switch (ON or OFF). If Adjustment switch gets "ON" signal (+Vcc) then the data are written into microcontroller and displayed on the 7-segment display. In other direction if the adjustment switch gets "OFF" signal (ground) then the microcontroller writes data into RTC and displays time on the 7-segment display with am/pm mode by LED indication and also displays day by 74LS138 decoder IC indication. After that data are read from RTC and displayed time on the 7-segment display. The whole processes are repeated to execute the operation of the smart digital clock until to shutdown the system.

Setup for Proposed Method
The program is written in C programming language with "Mikro C Pro" environment in order to meet the requirement for interfacing of all components in the system and the whole model is simulated with Porteus software [12]. 7-segment LED display is used to show up time and also nine LEDs are used to indicate am/pm mode as well as day of a week. To provide power to the system, 5 volt dc adopter and 3v backup battery are used to operate Real Time Clock DS1307 and 74LS138 decoder IC respectively. Communication between PIC 16F877A microcontroller and DS1307 can be established through I2C bus protocol.

PIC Microcontroller Tool 'MIKRO C PRO'
The "MIKRO C PRO" for PIC is a powerful feature-rich development tool for PIC microcontroller [13]. It is designed to provide the programmer with the convenient possible solution to developing applications for embedded systems, without compromising performance or control. The MIKRO C PRO is used to write program that has been used to execute operation of the smart digital clock [14]. This program has been written with "MIKRO C PRO" programming environment for PIC microcontroller.

Initial Time Setting and Data Writing on RTC Clock
The circuit diagram of smart digital clock is simulated in Proteus Software and then implemented practically as shown in figure 3. Port A of PIC 16F877A microcontroller is declared as an input pins by which can control to setup the initial time and day of this digital clock. Port B and Port D are declared as output pins that are connected with 7-segment display and base of transistor in order to display real time on the seven 7-segment display.
In Port C, pin RC3 and pin RC4 are connected with RTC DS1307 in order to write/read time and day by the microcontroller. Pin RC0 and RC1 are used as an output pins, those pins are needed to indicate am/pm mode of digital clock via LED indicator. Port E is used as output pins that are connected with input pin of 74LS138 decoder in order to meet the requirements of day display through seven LEDs indicator. Pin 11 and pin 12 are used to deliver power supply to the microcontroller, although those pins are hidden in this simulation but practically needed. Pin 13 and Pin 14 are interconnected with 20MHz Crystal that needed to operate microcontroller. Moreover pin 1 is used as RESET pin of PIC 16F877A Microcontroller. When designed system is enable/powered, it executes the sequential operation according to programming which is loaded within PIC 16F877A microcontroller. First of all, microcontroller cheeks the initial condition of switch of SW1 (PORTA. F3), if SW1 is connected with higher potential (+Vcc), the microcontroller gets interrupt signal and goes to store the initial data into itself [12]. The buttons (PORTA. F0, PORTA. F1) across the resistor R16 and R17 are pressed to initiate minutes and hours respectively and switch SW2 (PORTA. F2) is used to set am/pm mode. The day mode of a week can be setup through the button switch (PORTA. F4) across resistor R20 when SW1 is connected with +Vcc. Microcontroller waits to initiate time and date of RTC DS1307 until SW1 is connected with +Vcc. If SW1 is connected with ground potential, microcontroller sends data to write into the DS1307 RTC [13]. The following code segment represents the initial time setting and data writing on RTC clock

Reading Data from RTC Clock and Display on 7-Segment
PIC 16F877A microcontroller reads the data from DS1307 RTC and display time on 7-segment display with am/pm mode of operation. Every 24 hours, microcontroller increases the value of day by 1 and passes to the 74LS138 decoder IC through port E. However the decoder provides high output to the next one that indicates the next day [13]. Once more to setup the time, it is needed to set switch SW1 to +Vcc and then required to press the reset button which is connected with pin 1 of the microcontroller; consequently, time, day and am/pm mode can be set with help of others switches. The following code segment represents the data reading from DS1307 RTC and displaying data on the 7-segment display.

Result Analysis
The output is very significant and perceptible on 7segment display in smart way. The accuracy level is entirely high, trustworthy significant and implementable possible versatile arena. The following table 1 shows the initial setting and the result after first iteration in regarding some constraints. Table 2 shows the outcome both in 7-segment display and RTC clock when PORTA. F3 is null that means PORTA. F3 is connected with ground instead of +Vcc. At this stage, updated time at microcontroller will be written at DS1307 RTC by PIC 16F877A microcontroller. Table 3 shows the continuous outcome both in RTC clock and 7-segment display after data are written into DS1307 RTC. At this phase, PORTA. F3 is also NULL and time will be updated by one second. The smallest unit of time such as 'SECOND' is generated at DS1307 RTC by its own function. The updated data are read by the PIC 16F877A microcontroller in every second and send it to the 7-segment display.

Conclusion
In the proposed model, simple smart digital clock has been designed using single microcontroller and implemented practically after the simulation. However, most of the digital clock cannot provide the time exactly for longer period due to unstable effect of clocking pulse. Nevertheless, our designed smart digital clock is not affected by the unstable effect of clocking pulse problem because it uses Real Time Clock module DS1307 that keeps track of the system time and updates continuously.
Another data loss problem occurs in some digital clocks whenever power supply shuts down, but our designed smart digital clock is fully free from this hamper due to using of DS1307 RTC which has built-in power sense circuit that detects power failures and automatically switch 3V Li cell battery which is attached with the RTC provided by manufacturer. Moreover its circuit's complexity is very low even visually understandable and cost effective.