Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ds1307 rtc ram read and write issue

Status
Not open for further replies.

raman00084

Full Member level 6
Joined
Nov 29, 2010
Messages
362
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
4,006
the s1307 rtc has 56x8 ram. please send sample program for writing and reading in ram. i am using pic ccs complier
kindly send sample program are algorithim
 

Here is sample code for pic18f by using C18 compiler. Before this, once go through the ds1307 data sheet and pic i2c registers
How to start & stop i2c.......
Code:
void  rtc_setTime()
{
//i2c_Wait();
i2c_start();
i2c_write(0xa2);
i2c_write(0x02);
i2c_write (0x00) ; //set sec
i2c_write( 0x00);  //min
i2c_write(0x10);   //hou      10:59:00;
i2c_stop();
}
void  rtc_getTime()
{
i2c_Wait();
i2c_start ( ) ; //transmit  START  condition

i2c_write (0xa2) ;
i2c_write (0x02);
i2c_stop();

i2c_start ( ) ;
i2c_write(0xa3);

seconds =  i2c_read(1) ;
minutes =  i2c_read(1) ;
hours  =  i2c_read(0);
i2c_stop ( ) ;

seconds=seconds&0x7f;
minutes =minutes &0x7f;
hours  = hours &0x3f;

  seconds  =  ((seconds & 0xf0) >> 4)*10 + (seconds & 0x0F);  // Transform seconds
  minutes  =  ((minutes & 0xf0) >> 4)*10 + (minutes & 0x0F);  // Transform minutes
  hours    =  ((hours & 0xf0)  >> 4)*10  + (hours & 0x0F);    // Transform hours

hexmin=minutes;
  LCDCmd(0xCC);
  LCDWriteInt( seconds,2);
    LCDCmd(0xCB);
  LCDWriteString(":");
  LCDCmd(0xC9);
  LCDWriteInt( minutes,2);
  LCDCmd(0xC8);
  LCDWriteString(":");
  LCDCmd(0xC6);
  LCDWriteInt( hours,2);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top