Hello Peter
This is my DS1307.inc , my include file that I use for RTC clocks it works! Also note I find the DS1307 a poor RTC as it is not calibrated and thus can be out by minutes per month the better choice is the RX8025 with a calibrated crystal with maybe 10 seconds per month cost wise they are about the same.
Regards Paul.
[code:1:30f62d5ce6]
'called from ds1307clock.lib so a DS1307 could be used as they both are similar but
'the RX8025 has its own internal crystal which has been calibrated at the factory
'so it has a higher accuracy it also has an alarm function
Getdatetime:
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
I2crbyte Weekday , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return
Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 3 ' starting address in 1307
I2cwbyte Dayweek
I2cwbyte _day ' Send Date
I2cwbyte _month ' MINUTES
I2cwbyte _year ' Hours
I2cstop
Return
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
[/code:1:30f62d5ce6]
↧