Hi there,
I have setup a 16F690 reading a DS1307's time and date (I use RA2/INT interrupt to trigger the process every second), save this data to an external 24LC64 memory, read back what has just been written from the memory and display it.
If I bypass the I2CWRITE/I2CREAD commands, the DS1307 displays time correctly.
But, like in the code here under, after saving RTC's time to the memory, this is what I get after reading back the data from the external memory:

Data from DT1307 is in BCD format and data conversion, that's where I think I'm wrong, is not my cup of tea 
What am I missing?
Code:
'-------------------------------------------------------------------------------
' PIC 16F690 Fuses (MPASM)
@ __Config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
'-------------------------------------------------------------------------------
' Registers 76543210
OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB) INTEDG rising edge on A2
ANSEL = %00000000 'Analog inputs Channels 0 to 7
ANSELH = %00000000 'Analog inputs Channels 8 to 11
ADCON0 = %00000000 'A/D Module is OFF
CM1CON0 = %00000000 'Comparator1 Module is OFF
CM2CON0 = %00000000 'Comparator2 Module is OFF
INTCON = %00010000 'INTerrupts CONtrol
TRISA = %00000100 'Set Input/Output (0 to 5)
PORTA = %00000000 'Ports High/Low (0 to 5)
TRISB = %00010000 'Set Input/Output (4 to 7)
PORTB = %00000000 'Ports High/Low (4 to 7)
TRISC = %00000000 'Set Input/Output (0 to 7)
PORTC = %00000000 'Ports High/Low (0 to 7)
'-------------------------------------------------------------------------------
' Defines
DEFINE OSC 4
'-------------------------------------------------------------------------------
' Variables
SQW VAR PORTA.2 'DS1307's 1Hz output
D_Out VAR PORTB.7 'serial data out for display
SCL VAR PORTC.0 'DS1307 clock line
SDA VAR PORTC.1 'DS1307 data line
DB0 VAR BYTE(8)
DB0(0) = 0 ' Seconds (00-59)
DB0(1) = 0 ' Minutes (00-59)
DB0(2) = 0 ' Hours (00-23)
DB0(3) = 0 ' Day (01-07; 1=Sunday, 2=Monday, ...)
DB0(4) = 0 ' Date (01-31)
DB0(5) = 0 ' Month (01-12)
DB0(6) = 0 ' Year (00-99)
DB0(7) = 0 ' Control (see datasheet)
D_Bps CON 16468 ' 9600 Driven Inverted None
'-------------------------------------------------------------------------------
' Initialize
'-------------------------------------------------------------------------------
' Program
ON INTERRUPT GOTO Read_DS1307
MAIN:
GOTO MAIN:
END
'-------------------------------------------------------------------------------
' Interrutp Service Routine
DISABLE
Read_DS1307: ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control
I2CREAD SDA,SCL,$D0,$00,[STR DB0\8] ' Read 8 bytes from DS1307
' Write to external memory
I2CWRITE SDA,SCL,$A0,$00,[DB0(2),DB0(1),DB0(0)]
PAUSE 10
'Read from external memory
I2CREAD SDA,SCL,$A0,$00,[DB0(2),DB0(1),DB0(0)]
SEROUT2 D_Out,D_Bps,[HEX2 DB0(2),":",HEX2 DB0(1),":",HEX2 DB0(0),13,10]
INTCON.1 = 0 'clear INTF interrupt flag
RESUME
ENABLE
Bookmarks