Define CONFIG = 0x0194 'attempt i2c lcd backpack on 12f675 '************************************************* 'adjust osccal ASM: Call 0x03ff ASM: bsf status,5 ASM: movwf OSCCAL ASM: bcf status,5 '************************************************* CMCON = 7 ANSEL = 0 Symbol SCL = GPIO.2 Symbol SDA = GPIO.1 Dim slave_addr As Byte Dim backlight As Bit slave_addr = 0x4e WaitMs 10 '************************************************************************* I2CPrepare SDA, SCL set_backlight 1 lcd_begin lcd_setcursor 0, 1 lcd_print "abracadabra" more: lcd_setcursor 0, 0 lcd_print "is this line 2?" WaitMs 5000 lcd_setcursor 0, 0 lcd_print "now for fun " WaitMs 5000 Goto more End 'this will be called by send_nibble Proc write2wire(halfbyte As Byte, is_data As Bit, enable_data As Bit) Dim i2cdata As Byte i2cdata = ShiftLeft(halfbyte, 4) If is_data Then i2cdata = i2cdata Or 0x01 Endif If enable_data Then i2cdata = i2cdata Or 0x04 Endif If backlight Then i2cdata = i2cdata Or 0x08 Endif I2CStart I2CSend slave_addr I2CSend i2cdata I2CStop End Proc Proc lcd_begin() 'initialize display Dim function_flag As Byte Dim temp As Byte function_flag = 0x08 'lines are > 1 (see arduino .cpp) write2wire 0, 0, False WaitMs 50 send_nibble 0x03, 0 WaitUs 4500 send_nibble 0x03, 0 WaitUs 200 send_nibble 0x03, 0 WaitUs 200 send_nibble 0x02, 0 '4 bit interface temp = 0x20 Or function_flag send_byte temp, 0 lcd_display lcd_clear left_to_right End Proc Proc left_to_right() send_byte 0x06, 0 '0x04 or entrymode End Proc Proc lcd_display() 'turn display on tho we don't turn it off Dim temp As Byte temp = 0x04 Or 0x08 'display control= 0x08 or 0x04(on) send_byte temp, 0 End Proc Proc lcd_setcursor(col As Byte, row As Byte) 'sets ddram address Dim temp As Byte If col >= 0 And col < 16 And row >= 0 And row < 2 Then If row = 1 Then col = col + 0x40 Else col = 0 Endif temp = 0x80 Or col send_byte temp, 0 Endif End Proc Proc set_backlight(barg As Bit) If barg = 1 Then backlight = 1 Else backlight = 0 Endif write2wire 0, 1, 0 End Proc Proc lcd_clear() send_byte 0x01, 0 WaitUs 1600 End Proc Proc lcd_print(lcdstr As String) Dim temp As String Dim length As Byte Dim lchar As Byte lchar = 1 length = Len(lcdstr) While length > 0 temp = MidStr(lcdstr, lchar, 1) lcd_write temp lchar = lchar + 1 length = length - 1 Wend End Proc Proc lcd_write(ch As Byte) 'send characters to lcd send_byte ch, True End Proc Proc send_byte(value As Byte, is_data As Bit) Dim temp As Byte temp = ShiftRight(value, 4) temp = temp And 0x0f send_nibble temp, is_data temp = value And 0x0f send_nibble temp, is_data End Proc Proc send_nibble(half_byte As Byte, is_data As Bit) write2wire half_byte, is_data, True WaitUs 1 write2wire half_byte, is_data, False WaitUs 37 End Proc