Difference between revisions of "A6.8051 Interfacing: RTC DS1307"
Line 82: | Line 82: | ||
[[File:{{#setmainimage:RTC Interfacing with 8051.jpeg}}|x480px]] | [[File:{{#setmainimage:RTC Interfacing with 8051.jpeg}}|x480px]] | ||
}} | }} | ||
− | [[File:Download Icon.jpeg|thumbnail|link=http://xplorelabz.com/wiki/ | + | [[File:Download Icon.jpeg|thumbnail|link=http://xplorelabz.com/wiki/images/8/87/Real_time_clock_ds1307_with_8051.zip|8051_DS1307_RTC_Interfacing]] |
{{#widget:Facebook_Like_Box|profile=http://www.facebook.com/XploreLabz}} | {{#widget:Facebook_Like_Box|profile=http://www.facebook.com/XploreLabz}} | ||
{{#seo: | {{#seo: |
Revision as of 16:05, 26 January 2014
Basics
The Real time clock DS1307 IC basically is stand alone time clock. Well, basically we can use a micrcontroller to keep time, but the value would go off as soon as it is powered off.
The RTC DS1307 is a handy solution to keep time all the way, when it is powered by a coin cell.
It is uses I²C (Inter-Integrated Circuit) protocol, referred to as I-squared-C, I-two-C, or IIC) for communication with the micrcontroller.Check the basics of I2C here, if are not familiar with it.
Schematic
The schematic is very simple, LCD is connected in 4 bit mode.
The Serial Clock (SCL) from DS1307 RTC is connected to P3.6 of 8051 and Serial Data(SDA) is connected to P3.7 of 8051.
The lines are pulled up for stable voltages.
Code
The main program
#include <reg51.h> #include "lcd.h" // xplore labz lcd library #include "ds1307.h" // Xplore Labz RTC library /* start the main program */ void main() { unsigned char sec,min,hour,day,month,year; /* Initilize the lcd before displaying any thing on the lcd */ LCD_Init(); /* Initilize the RTC(ds1307) before reading or writing time/date */ DS1307_Init(); /*Set the time and Date only once */ DS1307_SetTime(0x10,0x40,0x20); // 10:40:20 am DS1307_SetDate(0x26,0x01,0x14); // 26th January 2014 /* Display "Time" on first line*/ LCD_DisplayString("Time: "); /* Display "Date" on Second line*/ LCD_GoToLineTwo(); LCD_DisplayString("Date: "); /* Display the Time and Date continously */ while(1) { /* Read the Time from RTC(ds1307) */ DS1307_GetTime(&hour,&min,&sec); /* Display the time on Firstline-7th position*/ LCD_GoToXY(0,6); LCD_DisplayRtcTime(hour,min,sec); /* Read the Date from RTC(ds1307) */ DS1307_GetDate(&day,&month,&year); /* Display the Date on Secondline-7th position*/ LCD_GoToXY(1,6); LCD_DisplayRtcDate(day,month,year); } }
The libraries
The library files and functions used in the example can be found in 8051_Family_C_Library
You may also download the entire project code at the bottom of the page.
The Results
{{#widget:Facebook_Like_Box|profile=http://www.facebook.com/XploreLabz}} {{#seo: |title=RTC Interfacing with 8051 |titlemode=append |keywords=8051,AT89s51,at89c51,p89v51rd2,XploreLabz,DS1307, Real time Clock |description= This tutorial describes interfacing Real time clock DS1307 with 8051 micrcontroller using I2C }} }
Have a opinion, suggestion or feedback about this article, let it out here!