$lib "mcsbyte.lbx" ' use the byte lib since we do not need longs $regfile = "8535def.dat" $crystal = 7372800 $baud = 19200 Declare Sub Settime(byval S1 As Byte , Byval M1 As Byte , Byval H1 As Byte , Byval D1 As Byte , Byval Month1 As Byte) Declare Sub Setalert(byval S1 As Byte , Byval M1 As Byte , Byval H1 As Byte , Byval D1 As Byte , Byval Month1 As Byte) Declare Sub Gettime() Dim Tm(5) As Byte At &H60 Dim I As Byte , Temp As Byte Dim S As Byte At &H60 Overlay Dim M As Byte At &H61 Overlay Dim H As Byte At &H62 Overlay Dim D As Byte At &H63 Overlay Dim Month As Byte At &H64 Overlay Dim Cnt As Byte Config Int0 = rising On Int0 Alarm Enable Int0 Enable Interrupts Config I2cdelay = 5 ' default slow mode Config Sda = Portd.7 Config Scl = Portd.6 Cnt = 31 Call Settime(0 , 30 , 13 , 12 , 1) 'set time Call Setalert(0 , Cnt , 13 , 12 , 1) Do Call Gettime Print Hex(h) ; ":" ; Hex(m) ; ":" ; Hex(s) ; " Err:" ; Err ; "--- " ; Hex(d) ; ":" ; Hex(month) Wait 1 Loop End Sub Gettime() Tm(1) = 2 I2creceive &HA0 , Tm(1) , 1 , 5 End Sub Sub Settime(s1 As Byte , M1 As Byte , H1 As Byte , D1 As Byte , Month1 As Byte) Tm(1) = Makebcd(s1) 'seconds Tm(2) = Makebcd(m1) 'minutes Tm(3) = Makebcd(h1) 'hours Tm(4) = Makebcd(d1) 'days Tm(5) = Makebcd(month1) 'months I2cstart 'generate start I2cwbyte &HA0 'write address I2cwbyte 0 'select control register I2cwbyte &B00000100 'alarm enable 'I2cwbyte &B00000000 'select control register I2cstart 'repeated start I2cwbyte &HA0 'write mode I2cwbyte 2 'select seconds Register For I = 1 To 5 I2cwbyte Tm(i) Next 'write seconds I2cstop End Sub Sub Setalert(s1 As Byte , M1 As Byte , H1 As Byte , D1 As Byte , Month1 As Byte) Tm(1) = Makebcd(s1) 'seconds Tm(2) = Makebcd(m1) 'minutes Tm(3) = Makebcd(h1) 'hours Tm(4) = Makebcd(d1) 'days Tm(5) = Makebcd(month1) 'months I2cstart I2cwbyte &HA0 'write address I2cwbyte 8 'jmp to control/status register I2cwbyte &B10110000 'alarm control register I2cwbyte &B00000000 '100tel I2cwbyte Tm(1) 'sec I2cwbyte Tm(2) 'min I2cwbyte Tm(3) 'hours I2cwbyte Tm(4) 'date I2cwbyte Tm(5) 'month I2cwbyte &B00000000 'alarm timer I2cstop End Sub Alarm: Print "hallo" Wait 1 I2cstart 'generate start I2cwbyte &HA0 'write address I2cwbyte 0 'select control register I2cwbyte &B00000100 'alarm enable I2cstop Print "reloaded" Incr Cnt Print Cnt waitms 200 Call Setalert(1 , Cnt , 13 , 12 , 1) Return