$regfile "m16def.dat" $crystal = 1000000 Config Scl = Porta.7 Config Sda = Porta.6 Config Lcdpin = Pin , Db7 = Porta.5 , Db6 = Porta.4 , Db5 = Porta.3 , Db4 = Porta.2 , Rs = Porta.0 , E = Porta.1 Config Lcd = 16 * 2 Deflcdchar [0] , 14 , 17 , 21 , 23 , 17 , 17 , 14 , 32 Dim Hour As Byte Dim Mine As Byte Dim Seco As Byte Dim Day As Byte Dim Dat As Byte Dim Month As Byte Dim Year As Byte Day = Makebcd(28) I2cstart I2cwbyte &HD0 I2cwbyte 3 I2cwbyte Day I2cstop Initlcd Cls Cursor Off Locate 1 , 1 Lcd "LCD1602 Clock " Lowerline Lcd "RTC DS1307 " ; Chr(0) Wait 2 Cls Locate 1 , 3 Lcd ":" Locate 1 , 6 Lcd ":" Locate 2 , 3 Lcd "." Locate 2 , 6 Lcd "." Locate 1 , 1 Do I2cstart I2cwbyte &HD0 I2cwbyte &H00 I2cstart I2cwbyte &HD1 I2crbyte Seco , Ack I2crbyte Mine , Ack I2crbyte Hour , Ack I2crbyte Day , Ack I2crbyte Dat , Ack I2crbyte Month , Ack I2crbyte Year , Nack I2cstop Seco = Makedec(seco) Mine = Makedec(mine) Hour = Makedec(hour) Day = Makedec(day) Dat = Makedec(dat) Month = Makedec(month) Year = Makedec(year) If Hour < 10 Then Locate 1 , 1 Lcd "0" ; Hour Else Locate 1 , 1 Lcd Hour End If If Mine < 10 Then Locate 1 , 4 Lcd "0" ; Mine Else Locate 1 , 4 Lcd Mine End If If Seco < 10 Then Locate 1 , 7 Lcd "0" ; Seco Else Locate 1 , 7 Lcd Seco End If If Day < 10 Then Locate 2 , 1 Lcd "0" ; Day Else Locate 2 , 1 Lcd Day End If If Month < 10 Then Locate 2 , 4 Lcd "0" ; Month Else Locate 2 , 4 Lcd Month End If If Year < 10 Then Locate 2 , 7 Lcd "0" ; Year Else Locate 2 , 7 Lcd Year End If Locate 2 , 12 Lcd Dat Loop