Define I2CREAD_DELAYUS = 400
Define I2CCLOCK_STRETCH = 10
'define the SDA and SCL channels , The actual internal I2C pins are PORTB.0 and B.1 which I am using for SD Cards and radio transceivers.
Symbol sda = PORTC.1
Symbol scl = PORTC.2
'interrupt
On Low Interrupt
Save System
INTCON.TMR0IF = 0
iflag = 1
read_rtc:
I2CStart
I2CSend 0xd0 'DS3231 slave addr wr
WaitUs 10
I2CSend 0x00 'first word addr wr
I2CStop
WaitUs 10
I2CStart
I2CRead sda, scl, 0xd1, 0, secs
I2CRead sda, scl, 0xd1, 1, mins
I2CRead sda, scl, 0xd1, 2, hrs
I2CRead sda, scl, 0xd1, 3, day
I2CRead sda, scl, 0xd1, 4, date
I2CRead sda, scl, 0xd1, 5, mnth
I2CRead sda, scl, 0xd1, 6, year
I2CRead sda, scl, 0xd1, 0x11, temph
I2CRead sda, scl, 0xd1, 0x12, templ
I2CStop
TMR0 = 0xff
INTCON.TMR0IE = 1
Resume