include "C:\PIC_code\MODULES\I2C_Subs_16bitbuffer.bas" 'Setup I2C Routines ClockAddr con %11010000 ; DS3231 Device address ;=============================================================================== ;---=== Initialize ===--- ;=============================================================================== ;Init Init_RTC: I2CAddr = ClockAddr : I2CWRSize = 2 ;Resest RTC Alarms I2CWRBuff(0) = $E: I2CWRBuff(1) = %0000000: Gosub WriteXBytes I2CWRBuff(0) = $F: I2CWRBuff(1) = 0: Gosub WriteXBytes ;Set RTC Data I2CWRSize = 7 :I2CAddr = ClockAddr I2CWRBuff(0) = 0 ;Seconds I2CWRBuff(1) = 0 ;Minutes I2CWRBuff(2) = 0 ;Hours I2CWRBuff(3) = 0 ;Day I2CWRBuff(4) = 0 ;Date I2CWRBuff(5) = %00000101 ;Month I2CWRBuff(6) = %00010010 ;Year Gosub WriteXBytes ;=============================================================================== ;---=== Main Loop ===--- ;=============================================================================== MainLoop: ;Get Time from RTC I2CWRBuff(0) = 0:I2CAddr = ClockAddr: Gosub Write1Byte ;Set Pointer I2CRDSize = 8: Gosub ReadXBytes Pause 1000 goto MainLoop