A PIC Real Time Clock IC (RTC) Using The DS1307
A PIC Real Time Clock IC (RTC) Using The DS1307
http://www.best-microcontroller-projects.com/real-time-clock-ic.html
Custom Search
Home Forum Problem?-Solution Projects Showcase LCD-Keys one port PIC Introduction PIC Programming Programmer Types PIC Programmer Schematic Tool PIC Projects TIPS & Techniques PIC Tutorials C Course Digital Downloads Store My Secret Oscilloscopes Contact Me About Me Terms of Use Search This Site Articles MicroBlog Books Resource Links Site Map Privacy Policy
This PIC project uses an I2C Real Time Clock IC (DS1307) and a four digit seven segment display to create a standard desk clock. Sign up for MicroZine ''The'' Microcontroller New
Name: E-Mail:
Note: If you typed DS1703 Real Time Clock to find this page you probably mis-spelled the chip type. Anyway you can find a DS1307 (RTC) Real Time Clock IC project and information here. Specification Accuracy Compiler Target Software level Software notes Hardware level Hardware notes Project version 1.00 Project version 1.01 Watch crystal spec typically 20ppm Mikroelectronika C compiler V5.0.0.3 Free! 16F88 (retargetable to other PICs that have Analogue input AN0). Medium. Switching between i/p & o/p to read analogue/drive display. Using I2C routines. Easy. Special care must be taken in placing the DS1307 and the crystal. Initial Release For battery backup lost seconds as power applied solved by not writing to chip at all if already initialised. Enter your details to get the Download Link and get the microcontroller newsletter: Your Name: Project files Primary E-Mail:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Enter your first Name and prima email address in the form above And receive absolutely FREE project for:
Now
(Note: Your email is safe it will never be sold or rented).
You will get All the C source code and hex file.
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website. You can only get it through this newsletter
To get exclusive access Enter your first name Nam and primary email address Now in the form above
But wait !
1 of 6
12/23/2011 12:47 PM
http://www.best-microcontroller-projects.com/real-time-clock-ic.html
Although the PIC16F88 has a built in oscillator for a 32kHz watch crystal a DS1307 is easier to use on a bread board. This is because you can control the layout of the circuit more easily. The RTC also makes the software easier as it takes care of all calendar functions; accounting for leap years etc. The DS1307 (RTC) Real Time Clock IC (an I2C real time clock) is an 8 pin device using an I2C interface (although the data sheet does not mention I2C to avoid royalty payments!). It has 8 read/write registers that store the following information: Address 0 1 2 3 4 5 6 7 Note: Addresses 0x08 to 0xf3 are user RAM and if you use a backup battery these are then non volatile ram i.e. they will save their contents after the power is off - so you have an extra 56 bytes of ram to play with! Note: Address 3f is used in this project as a check to see if the clock needs initialising and to store the upper year digit (for easier coding). The last address 0x08 is the CONTROL address and it determines what is generated at the SQW/OUT pin. You can control the level directly via I2C or set it to 1Hz, 4096Hz, 8192Hz, or 32768kHz. In the same way as the I2C pins you need to add a pull-up to V+ at the SQW/OUT pin to see any output signal as it is an open drain output!
There's more...
You'll receive more free and exclusive reports as well as site information and si product updates.
Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it you can unsubscribe at any tim Click Here Now to use the form above to get your Valuable information absolutely free.
Social Bookmarking
Click & Add: Blink Del.icio.us Digg Furl Google Simpy Spurl
Technorati
Y! MyWeb
Readers comments
"I wanted to thank you so so so much for all the information you have provided in your site it's
SUPERB and FANTASTIC ."
- Ranish Pottath
"This site really is the best and my favorite. I find here many useful projects and tips." - Milan bursach<at>gmail.com
Wondering how to program your next project using C and need a great start? "First Module Free:" CLICK HERE
2 of 6
12/23/2011 12:47 PM
http://www.best-microcontroller-projects.com/real-time-clock-ic.html
Using the DS1307 lets you put the crystal in the least noisy part of the board. In addition it sets the crystal load capacitance which is critical in making the crystal oscillate at exactly 32kHz - controlling its initial error i.e. for the specified ppm error value the load capacitance must be exact. Note: A common way of calibrating a crystal (not in this project) is crystal pulling or changing the capacitance at one crystal pin relative to the other so load capacitance is crucial. The DS1307 loads the crystal with 12.7pF so you need to buy a crystal that is defined to use this load capacitance. Circuit layout also affects the capacitance at the crystal pins so you must keep the crystal as close as possible to the chip and the tracks from crystal to chip must be short. To ensure the crystal oscillates correctly you must ensure that : Crystal uses 12.7pf load capacitance (correct crystal type). The crystal is close to the IC. The tracks are short. The chip supply has lots of decoupling (capacitors from +5V to GND). e.g. A 100n and a 10n There are no signal tracks near to the crystal. For a pcb: It has a guard ring and a ground plane and away from digital signals. If you are doing a board layout there is good advice in the PIC 16F88 datasheet (Timer 1 section) on crystal pcb guard rings. Dallas recommends Application note 58 which I have not read yet.
"I am a newbie to PIC and I wanted to say how great your site has been for me." - Dave de_scott<at>bellsouth.net
Learn Microcontrollers
"Interested in Microcontrollers?" Sign up for The Free 7 day guide: FREE GUIDE : CLICK HERE
"Your site is a great and perfect work. congratulations." - Suresh integratredinfosys<at> yahoo.com "I couldn't find the correct words to define yourweb site. Very useful, uncovered, honest and clear. Thanks so much for your time and works. Regards." - Anon
Input keys
To save microcontroller pins there are four input keys which are all connected to a single analogue input pin. This pin also drives one of the seven segment display LEDs so it has to be switched between input (to read the analogue voltage) and output (to drive the led). Each key pulls the analogue input to a different voltage level which you can easily read using the ADC (RA0).
3 of 6
12/23/2011 12:47 PM
http://www.best-microcontroller-projects.com/real-time-clock-ic.html
Mode button
Pressing mode button cycles the display showing different data after each button press. The following display sequence is followed: 1. 2. 3. 4. Minutes, Secs. Hours, Minutes. Date, Month. '20', Year.
You can use any PIC microcontroller that has an ADC and enough memory to hold the program and enough pins for the display multiplexing. You can program the PIC in circuit through the ICSP connector.
There is nothing realy difficult about the project except for placing the DS1307 away from noise sources and decoupling it as mentioned earlier. One point is that the multiplexed display does not use any current limit resistors that you would normally expect. You can get away with this if the display is on only for a very short time so that the average current out of the pin is kept small. Turning them on for a long time would draw too much current possibly damaging the microcontroller.
4 of 6
12/23/2011 12:47 PM
http://www.best-microcontroller-projects.com/real-time-clock-ic.html
Project files
Compiler project files 16F88_RTC_DS1307.ppc C Source files. 16F88_RTC_DS1307.c I2C.c Header files. bit.h - bit manipulation macros I2C.h Output files 16F88_RTC_DS1307.hex
Description
16F88_RTC_DS1307.c This contains the main routine and support functions for controlling the DS1307. init_ds1307() read_ds1307() write_ds1307() edit_ds1307() stop_ds1307() start_ds1307() These are all self explanatory. Also in the file are analogue key reader function read_ANA_keys() and display routines: int2seg() clock_display() int2seg() - Converts a number into the required output value for PORTA to drive the seven segment display. clock_display() - The complexity in this routine is for selectively blanking left or right pairs of digits so that they can be flashed on and off. Other complexity is preserving the control bits at addresses 0x00 and 0x02. Yet more complexity is in only turning on one seven segement display at each call to the routine. Other standard routines are included for port initialisation and general initialisation. I2C.c This contains the software implementation of I2C (clock stretching has not been tested). To change the PORTs/pins alter the #define statements at the start of I2C.c
Operation
Operation of the software follows the description given earlier in section "Using the Real time Clock IC project" The only other point to mention is the switching of the TRISA port for reading the ADC at the start of the while loop. This has to set the TRIS state correctly after the ADC read. And thats it - enjoy. Jump from Real Time Clock IC project to Best Microcontroller Projects Home Page. Share this page:
5 of 6
12/23/2011 12:47 PM
http://www.best-microcontroller-projects.com/real-time-clock-ic.html
Don't forget to Sign Up for your Microcontroller Newsletter With "Essential tips and techniques", ..."New Site Info" and more... Including a free project : How to drive an LCD and 12key keypad using "Only One 8 Bit Port" with no interface logic!...
(Works for any microcontroller)
This costs you : Nothing... Just fill out the form below and you'll get full C source code and project schematic and description.
Name: E-Mail:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Web
www.best-microcontroller-projects.com
6 of 6
12/23/2011 12:47 PM