$regfile = "m8def.dat" $crystal = 3686411 Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2 Config Lcd = 16 * 2 Config Pinb.0 = Input Config Pinb.1 = Input Config Pinb.2 = Input Config Sda = Portc.4 Config Scl = Portc.5 Const Ds1307w = &HD0 Const Ds1307r = &HD1 Config Clock = User Config Date = Dmy , Separator = / Config Debounce = 30 Cursor Off Do Locate 1 , 1 : Lcd "tarikh:" : Locate 1 , 8 : Lcd Date$ Locate 2 , 1 : Lcd "time:" : Locate 2 , 8 : Lcd Time$ Gosub Tanzimat Loop End Dim Weekday As Byte '----------------------------------- Getdatetime: I2cstart I2cwbyte Ds1307w I2cwbyte 0 I2cstart I2cwbyte Ds1307r I2crbyte _sec , Ack I2crbyte _min , Ack I2crbyte _hour , Ack I2crbyte Weekday , Ack I2crbyte _day , Ack I2crbyte _month , Ack I2crbyte _year , Nack 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 I2cwbyte Ds1307w I2cwbyte 4 I2cwbyte _day I2cwbyte _month I2cwbyte _year I2cstop Return Settime: _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour) I2cstart I2cwbyte Ds1307w I2cwbyte 0 I2cwbyte _sec I2cwbyte _min I2cwbyte _hour I2cstop Return Tanzimat: Debounce Pinb.0 , 0 , Second , Sub Debounce Pinb.1 , 0 , Minot , Sub Debounce Pinb.2 , 0 , Hour , Sub Return '--------------------------------------------- Second: Incr _sec If _sec > 59 Then _sec = 0 _sec = Makebcd(_sec) I2cstart I2cwbyte Ds1307w I2cwbyte 0 I2cwbyte _sec I2cstop Return '------------------------------------- Minot: Incr _min If _min > 59 Then _min = 0 _min = Makebcd(_min) I2cstart I2cwbyte Ds1307w I2cwbyte 1 I2cwbyte _min I2cstop Return '------------------------------------- Hour: Incr _hour If _hour > 23 Then _hour = 0 _hour = Makebcd(_hour) I2cstart I2cwbyte Ds1307w I2cwbyte 2 I2cwbyte _hour I2cstop Return End