'------------------- AN 4 ----------------------------- ' Copyright 1998 MCS Electronics ' CLOCK.BAS 'This AN shows how to use the PCF8583 I2C clock device 'The PCF8583 is a PHILIPS device. Look at the datasheet for more details 'I used a prototype board from dontronics with the hardware 'simulator to test the program '------------------------------------------------------ 'declare used subs Declare Sub Settime(s As Byte , M As Byte , H As Byte , D As Byte , Month As Byte) Declare Sub Gettime 'declare vairables Dim S As Byte , M As Byte , H As Byte , D As Byte , Month As Byte Dim Wm As Byte , Yd As Byte Call Settime(0 , 0 , 0 , 29 , 11) 'set time Do Call Gettime 'get time Loop End Sub Gettime Dim Dum As Byte I2cstart 'generate start I2cwbyte &HA0 'write addres of PCF8583 I2cwbyte 2 'select second register I2cstart 'generate repeated start I2cwbyte &HA1 'write address for reading info I2crbyte S , Ack 'read seconds I2crbyte M , Ack 'read minuts I2crbyte H , Ack 'read hours I2crbyte Yd , Ack 'read year and days I2crbyte Wm , Nack 'read weekday and month I2cstop 'generate stop Print "Time " ; Bcd(h) ; ":" ; Bcd(m) ; ":" ; Bcd(s) Print "Day : " ; Bcd(yd) ; " Month : " ; Bcd(wm) Lcd "Time " ; Bcd(h) ; ":" ; Bcd(m) ; ":" ; Bcd(s) Lcd "Day : " ; Bcd(yd) ; " Month : " ; Bcd(wm) Rem You Could Also Use The Lcd Statement For Displaying The Rem Time On The Lcd Display End Sub Sub Settime(s As Byte , M As Byte , H As Byte , D As Byte , Month As Byte) 'values are stored as BCD values so convert the values first S = Makebcd(s) 'seconds M = Makebcd(m) 'minuts H = Makebcd(h) 'hours D = Makebcd(d) 'days Month = Makebcd(month) 'months I2cstart 'generate start I2cwbyte &HA0 'write address I2cwbyte 0 'select control register I2cwbyte 8 'set year and day bit for masking I2cstop 'generate stop I2cstart 'generate start I2cwbyte &HA0 'write mode I2cwbyte 2 'select seconds Register I2cwbyte S 'write seconds I2cwbyte M 'write minuts I2cwbyte H 'write hours I2cwbyte D 'write days I2cwbyte Month 'write months I2cstop End Sub