Ds1307 Programming

Posted on
Wiring It Up

Complete guide about DS1307 RTC interfacing with 8051 microcontroller, rtc configuration, data framing, registers and rtc programming by using I2C protocol. DS1307 I2C RTC Interfacing Tutorial From Rikipedia Embedded Wiki. DS1307 is an i2c based serial real time clock (RTC). It is a very low power device with full BCD clock/calendar keep tracks of seconds, minutes, hours, date of month, month, day of month and year with leap year compensation which is valid upto year 2100.

A real time clock is basically just like a watch - it runs on a battery and keeps time for you even when there is a power outage! Using an RTC, you can keep track of long timelines, even if you reprogram your microcontroller or disconnect it from USB or a power plug.

Most microcontrollers, including the Arduino have a built-in timekeeper called millis() and theres also timers built into the chip that can keep track of longer time periods like minutes or days. So why would you want to have a seperate RTC chip? Well, the biggest reason is that millis() only keeps track of time since the Arduino was last powered - that means that when the power is turned on, the millisecond timer is set back to 0.

The Arduino doesnt know its 'Tuesday' or 'March 8th' all it can tell is 'Its been 14,000 milliseconds since I was last turned on'. OK so what if you wanted to set the time on the Arduino? You'd have to program in the date and time and you could have it count from that point on. But if it lost power, you'd have to reset the time. Much like very cheap alarm clocks: every time they lose power they blink 12:00 While this sort of basic timekeeping is OK for some projects, some projects such as data-loggers, clocks, etc will need to have consistant timekeeping that doesnt reset when the Arduino battery dies or is reprogrammed.

Thus, we include a seperate RTC! The RTC chip is a specialized chip that just keeps track of time. It can count leap-years and knows how many days are in a month, but it doesn't take care of Daylight Savings Time (because it changes from place to place) This image shows a computer motherboard with a Real Time Clock called the. Theres a lithium battery in there which is why its so big. Download Openmg Jukebox.

The RTC we'll be using is the. It's low cost, easy to solder, and can run for years on a very small coin cell. As long as it has a coin cell to run it, the DS1307 will merrily tick along for a long time, even when the Arduino loses power, or is reprogrammed. You MUST have a coin cell installed for the RTC to work, if there is no coin cell, it will act strangly and possibly hang the Arduino so ALWAYS make SURE there's a battery installed, even if its a dead battery. If you'd like to use the header to plug the breakout board into something, place the header in a breadboard, long side down and place the board so that the short pins stick thru the pads.

Solder them in place. Insert the battery so that the flat + side is UP. The battery will last for many years, 5 or more, so no need to ever remove or replace it. You MUST have a coin cell installed for the RTC to work, if there is no coin cell, it will act strangly and possibly hang the Arduino so ALWAYS make SURE there's a battery installed, even if its a dead battery. Any 5V microcontroller with I2C built-in can easily use the DS1307. We will demonstrate how to use it with an Arduino since it is a popular microcontroller platform. Cinema 4d Motion Plugin Download. For the RTC library, we'll be using a fork of JeeLab's excellent RTC library - a library for getting and setting time from a DS1307 (originally written by JeeLab, our version is slightly different so please only use ours to make sure its compatible!) - download the.zip by clicking on Download Source (top right) and rename the uncompressed folder RTClib in a folder called RTClib.