Read time from real time clock and EEPROM device- I2C bus
The
two I2C devices are on two different pairs of I2C bus lines (why?!)
EEPROM - (24LC64) - SDA-RC2, SCL-RC3
Clock - (PFC8583P) - SDA-RC1, SCL-RC0
Real
time Clock - I2C_clock.bas AllDigital Lcdinit 'Symbol scl = PORTC.3 Symbol scl = PORTC.0 'Symbol sda = PORTC.4 Symbol sda = PORTC.1 Dim addr As Byte Dim data As Byte Dim sec As Byte Dim min As Byte Dim hour As Byte Dim day As Byte Dim month As Byte Dim year As Byte Dim d_hi As Byte Dim d_lo As Byte WaitMs 1000 addr = 2 I2CWrite sda, scl, 0xa2, addr, 0 addr = 3 I2CWrite sda, scl, 0xa2, addr, 0x55 addr = 4 I2CWrite sda, scl, 0xa2, addr, 0x23 addr = 5 I2CWrite sda, scl, 0xa2, addr, 0xb1 addr = 6 I2CWrite sda, scl, 0xa2, addr, 0x12 loop: addr = 2 I2CRead sda, scl, 0xa2, addr, sec addr = 3 I2CRead sda, scl, 0xa2, addr, min addr = 4 I2CRead sda, scl, 0xa2, addr, hour addr = 5 I2CRead sda, scl, 0xa2, addr, day year = 0 year.0 = day.6 year.1 = day.7 day.6 = 0 day.7 = 0 addr = 6 I2CRead sda, scl, 0xa2, addr, month month.5 = 0 month.6 = 0 month.7 = 0 Lcdcmdout LcdClear Lcdout "Time: " data = hour Gosub print Lcdout ":" data = min Gosub print Lcdout ":" data = sec Gosub print Lcdcmdout LcdLine2Home Lcdout "Date: " data = day Gosub print Lcdout "/" data = month Gosub print Lcdout "/200", #year WaitMs 200 Goto loop End print: d_hi = data / 16 d_lo = data Mod 16 If d_hi < 10 Then Lcdout #d_hi Else Lcdout "X" Endif If d_lo < 10 Then Lcdout #d_lo Else Lcdout "X" Endif Return |
EEPROM
array AllDigital |