I2C LCD program for easy Text transfer

Applications, examples, and sample programs using products from Comfile Technology

I2C LCD program for easy Text transfer

Postby FloridaJo » Sun Sep 18, 2011 4:21 am

Code: Select all
Const Device = CB220 'it says that the cubloc is a cb220
'This was written for the NHD-0216K3Z-FL-GBW.
'Alter code for lines and number of characters for your display.
'this display is a 2 x 16 display. Modify code for other sizes.
'written in Cubloc Basic
'By Joel Godin http://www.godintechnolgies.com and Cubloc YouTube channel:  http://www.youtube.com/cublocprojects

Ramclear

Dim data1 As Byte      'I2C storage bin
Dim st1 As String      'Statement one
Dim st2 As String      'Statement two (just add more if you have more and change the address appropriately)
Dim cnt As Byte              'For counter


Set I2c 9,8 'set scl=8 and sda=9
I2cstart
data1 = I2cwrite(&h50) 'Default Address of New Haven LCD
   
data1 = I2cwrite(&hFE)   'Address HighByte for the LCD
data1 = I2cwrite(&h52)   'Set contrast command
data1 = I2cwrite 19      'contrast value 1 - 50.  You can send data in binary(&b11001100) hex(&hFE) or just AscII like here.

data1 = I2cwrite(&hFE)   'Address HighByte for the LCD
data1 = I2cwrite(&h51)   'Clear Screen command
I2cstop

'place holder below is not necessary but helps create spacing.  It is lined up with the line below in Cubloc studio.
'     [       ||       ]  16 character place holder inside of brackets.  Change for other length LCD's
st1 = "     Comfile"           'insert your first string here
st2 = "  Technologies"   'insert your second string here
writetoLCD                'call to subroutine to parse statements and send ASCII code to LCD
Delay 5000                'in this example, we're just throwing 2 statements with a delay between them.

'     [       ||       ]  16 character place holder inside of brackets. Change for other length LCD's
st1 = "    Project       "   'insert your string here
st2 = "  Begins today"    'insert your string here
writetoLCD

End


Sub writetoLCD()
I2cstart
data1 = I2cwrite(&h50)      'address LCD

data1 = I2cwrite(&hfe)      '3 below lines to set cursor to line 1.  This LCD always requires the HighByte of &hFE before the command
data1 = I2cwrite(&h45)
data1 = I2cwrite(&h00)      'set position to line 1

For cnt = 1 To 16            'clear out row loop
   data1 = I2cwrite 32      'I switch it up here and just write an ASCII code
Next

data1 = I2cwrite(&hfe)      '3 below lines to set cursor to line 1
data1 = I2cwrite(&h45)
data1 = I2cwrite(&h00)

For cnt = 1 To Len(st1)       'loop to parse statement 1 and write out each character
   data1 =  I2cwrite Asc(Mid(st1,cnt,1))
Next

data1 = I2cwrite(&hfe)      '3 below lines to set cursor to line 2
data1 = I2cwrite(&h45)
data1 = I2cwrite(&h40)      'set position to line 2

For cnt = 1 To 16            'clear out row
   data1 = I2cwrite 32
Next

data1 = I2cwrite(&hfe)      '3 below lines to set cursor to line 2
data1 = I2cwrite(&h45)
data1 = I2cwrite(&h40)

For cnt = 1 To Len(st2)      'st2 is second line statement
   data1 =  I2cwrite Asc(Mid(st2,cnt,1))
Next

I2cstop
End Sub
-- I'm really a machine--
FloridaJo
Super
 
Posts: 37
Joined: Mon Feb 11, 2008 6:21 pm

Return to Applications and Examples

Who is online

Users browsing this forum: No registered users and 2 guests

cron