hii,
i am finding problem with ds1307. it is interfaced to at89c51. the code is as follows:
void main() { init_timer(); //for lcd delay init_lcd(); set_time(); while(1) display_time(); }
void set_time() { rtc_start(); shiftout_rtc(RTC_WRITE); shiftout_rtc(0); shiftout_rtc(0x20); shiftout_rtc(0x00); //0x00 has no effect, on reading, i get //30 for minutes irrespective of the //value i send here. rtc_stop(); }
void display_time() { int i, j; char disp_buffer[2], seconds, minutes; rtc_start(); shiftout_rtc(RTC_WRITE); shiftout_rtc(0); rtc_start(); shiftout_rtc(RTC_READ); seconds = shiftin_rtc()&0x7f; send_ack(); minutes = shiftin_rtc()&0x7f; send_nack(); rtc_stop(); pass_cmd(0x80); sprintf(disp_buffer, "%x", seconds); for(j = 0; j < 2; j++) { pass_data(disp_buffer[j]); } pass_data(':'); sprintf(disp_buffer, "%x", minutes); for(j = 0; j < 2; j++) { pass_data(disp_buffer[j]); } }
void send_ack() { SCL_RTC = 1; delay_ep(100); SDA_RTC = 0; delay_ep(100); SCL_RTC = 0; delay_ep(100); }
void send_nack() {
SCL_RTC = 1; delay_ep(100); SDA_RTC = 1; delay_ep(100); SCL_RTC = 0; delay_ep(100); }
initial value got from reading the rtc is correct in case of seconds. it begins at 20, but increments bit slowly, in about 2 seconds. after
60, it becomes 0, then 10, 20, etc. also, minutes starts at 30 irrespective of the value i send, and doesn't increment properly. i use 32.768 watch xtal. there is no problem with rtc_start(), shiftout_rtc(), or rtc_stop() as they worked fine with an eeprom application i did earlier. i guess the trouble is with setting/reading the rtc, but i cant locate exactly.any help will be appreciated. thanx