hi sir, i am new to this rtc ds1307 and want to know dat according to its datasheet it is battery backed....does that mean that you need not initialize it when you use it for the first time?????
and if i want to simulate it on proteus software it shows correct date and time automatically without writing it for the first time.....
i m unable to understand all this plzzz help me out....and i m sorry if i irritated you...
It's really very simple:
Forget the fact that it's a "mysterious" semiconductor chip - just think of it as a clock. An ordinary, battery-operated clock.
If anyone gave you a battery-operated clock, would you just assume that it must have the correct time?
Of course not! You'd check it - wouldn't you?!
And you'd keep checking it from time to time - to make sure that the battery was still OK - wouldn't you?!
And, when the battery finally died, you'd have to re-set the clock after you'd replaced the battery - wouldn't you?!
No mystery here - just perfectly normal stuff for any battery-operated clock!
sir, i a using AT89S52 and rtc 1307 for my project. I have made this program to write and read the rtc but when i simulate it and see on lcd it gives me ??:??:?? this type of an output... i m not getting what type of mistake i am committing plz help me out to resolve this error.
#include<reg52.h> sfr lcddata=0x90; sbit rs=P3^2; sbit rw=P3^3; sbit en=P3^4; sbit SDA=P0^1; sbit SCL=P0^0; /*************************delay function*******************************************/ void delay(unsigned char b) { unsigned char a; for(b;b>1;b--) for (a=12;a>1;a--); } void delay2(unsigned int b) { unsigned int a,j; for(a=0;a<b;a++) for(j=0;j<120;j++); } /************************************Lcd initilization Command Function***********/ void command(unsigned char word) { en=1; rs=0; rw=0; delay(23); lcddata=word; en=0; } /******************************Display one word************************************/ void lcddisplay(unsigned word) { lcddata=word; en=1; rw=0; rs=1; delay(5); delay(5); en=0; } /***************************display lcd word second line***************************************/ void display(unsigned char *word) { int x; for(x=0;word[x]!=0;x++) { lcddisplay(word[x]); delay(5); } } /************************rtc initialaization************************************/ void I2c_start(void) { SDA = 1; delay(50) ; SCL = 1; //H-L Pulse delay(20) ; SDA = 0; delay(50) ; SCL = 0; delay(50) ; } void I2c_stop(void) { SCL = 0; delay(2) ; SDA = 0; delay(2) ; SCL = 1; // L-H pulse. delay(4) ; SDA = 1; delay(4) ; SCL = 0; } void I2c_write(unsigned char out_data) { unsigned char i; for(i=0;i<8;i++) { delay(2) ; SDA = ((out_data & 0x80)? 1:0 ); //checking MSB bit is '0' or'1' out_data <<=1; //used for sending the bit SCL = 1; delay(4) ; SCL = 0; delay(4) ; } i = SDA; delay(2); SCL = 1; delay(2); SCL = 0; } unsigned char I2c_read() { unsigned char i,in_data; in_data = 0x00; //Reset in_data for(i=0;i<8;i++) { in_data <<= 1; SCL = 1; in_data |= SDA; delay(5) ; SCL =0; delay(5) ; } return (in_data); } void init() { delay2(200); I2c_start(); I2c_write(0xA0); I2c_write(0x00); I2c_write(0x00); // data to be sent(Seconds) delay(1); I2c_write(0x57);//minutes delay(1); I2c_write(0x29);//hours delay(1); I2c_write(0x07);//days delay(1); I2c_write(0x02);//date delay(1); I2c_write(0x07);//month delay(1); I2c_write(0x0B);//year delay(1); I2c_write(0x83);//control delay(1); I2c_stop(); } /**************************BCD TO ASCII CONVERT ******************************************/ void bcdconv(unsigned char mybyte) { unsigned char x, y; x = mybyte & 0x0f; x = x | 0x30; y = mybyte & 0xf0; y = y>>4; y = y|0x30; lcddisplay(y); lcddisplay(x); } /************************main function******************************************/ void main() { //int k=1,i,l; unsigned char hr, min, sec, day, date, month, year; command(0x38); command(0x0C); command(0x80); command(0x01); init(); display("Tishitu welcome"); while(1) { command(0xC0); I2c_start(); I2c_write(0xA0); I2c_write(0x00); I2c_start(); I2c_write(0xA1); //hr = Read_EEPROM_byte1(0x02); sec = I2c_read(); //lcddisplay(sec); bcdconv(sec); display(":"); min = I2c_read(); //min = Read_EEPROM_byte1(0x01);; bcdconv(min); display(":"); hr = I2c_read(); bcdconv(hr); display(":"); day = I2c_read(); bcdconv(day); display(":"); date = I2c_read(); bcdconv(date); display(":"); month = I2c_read(); bcdconv(month); display(":"); year = I2c_read(); bcdconv(year); I2c_stop(); } }
The whole point of running code in a simulator is so that you can easily step through it and see exactly what is happening internally.
Doing that, you should be able to see exactly where it writes to the LCD, and what it attempts to write...
View all questions in Keil forum