Hi Malcolm.

I'm trying this code but can't make it work. It only displays:

Time= 00:00:00
Date= 00:00:00

but does not show the date and time that was set or advance.

Tried grounding DS1307's Vbat pin and using a lithium battery between this pin and ground. Tried 1k, 4.7K and 10k resistors to Vcc from SCL & SDA.

I know I can write to the DS1307 and I know it's ticking since I can make the SQWE pin stop or go 1 Hz by changing the last byte while writing, I just don't seem to be able to read from it.

I'm using a 16F887 at 4 mhz, pin PortB.1 is SCL, pin PortB.2 is SDA.

Any ideas?

Thanks!

Rogerio


Code:
DEFINE  OSC 4
CLEAR

;----[LCD definitions]------------------------------------------------------
DEFINE LCD_DREG  PORTC              ' LCD Data port
DEFINE LCD_DBIT  0                  ' starting Data bit (0 or 4)
DEFINE LCD_EREG  PORTD              ' LCD Enable port
DEFINE LCD_EBIT  0                  ' Enable bit  (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTD              ' LCD Register Select port
DEFINE LCD_RSBIT 1                  ' Register Select bit   (on EasyPIC 5 LCD)
'DEFINE LCD_BITS  4                  ' LCD bus size (4 or 8 bits)
'DEFINE LCD_LINES 2                  ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000           ' Command delay time in us 
DEFINE LCD_DATAUS 50                ' Data delay time in us 
SDA var PORTB.2                     ' RTC data 
SCL var PORTB.1                     ' RTC clock
DB0 var byte[8]

TRISB= %11111111
gosub write_1307
read_1307:                          ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control
I2CREAD SDA,SCL,$D1,$00,[STR DB0\8] ' Read 8 bytes from DS1307
lcdout $fe,1,"Time=",hex2 DB0[2],":",hex2 DB0[1],":",hex2 DB0[0]    'bit 0=sec, bit 1=min, bit 2=hrs
lcdout $fe,$c0,"Date=",hex2 DB0[4],":",hex2 DB0[5],":",hex2 db0[6]  'bit 4=day, bit 5=month, bit 6=year

goto read_1307
end

Write_1307:                          ' Set time & date to 19:00:00  14th Feb 201
pause 1000
I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$19,$7,$14,$2,$10,$80] ' Write to DS1307
pause 10
RETURN