i have done the interface between ds1307 and 89v51rd2.the output to uart after reading time and date from the rtc ic not correct i am getting like Time=36:32:0D,Date=1F/1C/3F.can any one help me.
i noticed on the unsigned int DS1307_get(unsigned char addr) that you return with this: ret is on BCD but when you apply return ((((ret>>4)&0x0F)*10)+(ret&0x0F)) that mean that the returned value is not on BCD why you apply BCD2HEX after this
"why you apply BCD2HEX after this"
Because the posted code is copy/paste from different sources, sprinkled with some manual changes?
"Because the posted code is copy/paste from different sources, sprinkled with some manual changes?"
Before you can start debugging you do, of course, have to understand what the system should do!
So the first step in debugging is to think about what should be happening. Then you need to think how that differs from what actually happens.
But it all still comes down to thinking: it's no use pressing the 'run' button and then just saying, "it doesn't work".
Now i'm sure that your software is wrong
first as tell rank amateur unsigned int DS1307_get(unsigned char addr) { unsigned int ret=0;
/* shouldn't you issue a start bit before the write ? */
I2C_write(DS1307_ID); /* Connect to DS1307 */
second : try too see with me this When you set the time you made
void DS1307_settime(unsigned char hh, unsigned char mm, unsigned char ss) { I2C_start(); I2C_write(DS1307_ID); /* connect to DS1307 */ I2C_write(0x00); /* Request RAM address at 00H */ I2C_write(ss); /* Write sec on RAM address 00H */ I2C_write(mm); /* Write min on RAM address 01H */ I2C_write(hh); /* Write hour on RAM address 02H */ //delay_20ms(20); I2C_stop(); /* Stop i2c bus */ }
you write on the adress 0 that means the start of second and you write on it ss,mm,hh when you write on the DS1307 the adress is incremented automatically 0x00,0x01,0x02 the same thing when you read but on your read subroutine you are reading just one value from the specified adress (adr) and each time you read the same adress where are the value of SEC,MIN,HOUR,DATE,MOTNH,YEAR ? i think if you don't specifie it will be take as '0'
sec = (DS1307_get(SEC)); delay_10ms(10); min = (DS1307_get(MIN)); delay_10ms(10); hour = (DS1307_get(HOUR)); delay_10ms(10); date = (DS1307_get(DATE)); delay_10ms(10); month = (DS1307_get(MONTH)); delay_10ms(10); year = (DS1307_get(YEAR)); delay_10ms(10);