'***PARA SIMULACION ****
Define CONF_WORD = 0x3d32
Define CLOCK_FREQUENCY = 12
'******Pic16F877A*******************
Define SIMULATION_WAITMS_VALUE = 1
AllDigital
'----------------------------------
Define LCD_BITS = 8
Define LCD_DREG = PORTD
Define LCD_DBIT = 0
Define LCD_RSREG = PORTE
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTE
Define LCD_RWBIT = 1
Define LCD_EREG = PORTE
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Lcdinit
'----------------------------------
Symbol scl = PORTC.3
Symbol sda = PORTC.4
'----------------------------------
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