Define CONFIG = 0x3f71
Define CLOCK_FREQUENCY = 4
Dim addr As Word 'variable for storing EEPROM byte address
Dim data As Byte 'variable for storing EEPROM byte data
Dim bl As Byte
Dim rs As Byte
Symbol sda = PORTC.4 'nickname for SDA pin
Symbol scl = PORTC.3 'nickname for SCL pin
bl = 0x8
rs = 0x1
Call i2clcdbegin()
Call printstr()
Call cmdwrite(0xc0)
Call printstr2()
End
Proc printstr()
Dim x As Byte
Dim ch As Byte
For x = 0 To 16
ch = LookUp(" Hello world!! "), x
Call datawrite(ch)
Next x
End Proc
Proc printstr2()
Dim x As Byte
Dim ch As Byte
For x = 0 To 16
ch = LookUp(" Dave Phillips "), x
Call datawrite(ch)
Next x
End Proc
Proc i2clcdbegin()
WaitMs 15
Call cmdwrite(0x33)
WaitMs 5
Call cmdwrite(0x32)
WaitMs 5
Call cmdwrite(0x2c)
WaitMs 1
Call cmdwrite(0xc)
WaitMs 1
Call cmdwrite(0x6)
WaitMs 1
Call cmdwrite(0x1)
End Proc
Proc datawrite(data As Byte)
Dim hi As Byte
Dim lo As Byte
lo = ShiftLeft(data, 4)
hi = data And 0xf0
lo = lo And 0xf0
data = hi + bl + rs
I2CWrite sda, scl, 0x4e, data, data
data = data + 0x4
I2CWrite sda, scl, 0x4e, data, data
data = data - 0x4
I2CWrite sda, scl, 0x4e, data, data
WaitMs 1
data = lo + bl + rs
I2CWrite sda, scl, 0x4e, data, data
data = data + 0x4
I2CWrite sda, scl, 0x4e, data, data
data = data - 0x4
I2CWrite sda, scl, 0x4e, data, data
End Proc
Proc cmdwrite(cmd As Byte)
Dim hi As Byte
Dim lo As Byte
lo = ShiftLeft(cmd, 4)
hi = cmd And 0xf0
lo = lo And 0xf0
cmd = hi + bl
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd + 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd - 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
WaitMs 1
cmd = lo + bl
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd + 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd - 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd