'//////////////////////////////////////////////////////////////////// '/// FastAVR Basic Compiler by MICRODESIGN, www.FastAVR.com /// '/// LCD I2C clock using PCF8583 /// '/// Clock8583.bas /// '//////////////////////////////////////////////////////////////////// $Device=4433 $Stack = 32 $Clock = 7,3728 $Lcd=PORTD.4, RS=PORTB.4, EN=PORTB.5, 16, 2 $I2C SDA=PORTB.0, SCL=PORTB.1 Declare Sub Settime(ure As Byte, Min As Byte, sec As Byte) Declare Sub Gettime() Dim h As Byte, m As Byte, s As Byte Const PCF8583=&ha0 Settime(12,12,12) 'set time for test Cls Locate 1,1: Lcd "Clock" Do Gettime() Locate 2,1 Lcd Hex(h);":";Hex(m);":";Hex(s) WaitMs 250 Loop '/////////////////////////////////////////////////// Sub Gettime() I2Cstart PCF8583 'generate start I2Cwrite 2 'select second register s=I2Cread, Ack m=I2Cread, Ack h=I2Cread, Nack I2Cstop 'generate stop End Sub '/////////////////////////////////////////////////// Sub Settime(ure As Byte, Min As Byte, sec As Byte) I2Cstart PCF8583 'generate start I2Cwrite 2 'select seconds Register I2Cwrite Bcd(sec) 'write seconds I2Cwrite Bcd(Min) 'write minutes I2Cwrite Bcd(ure) 'Write Hours I2Cwrite Bcd(0) 'write days I2Cwrite Bcd(0) 'write months I2Cstop End Sub