Connecting an LCD to an OOPic
This Application Note demonstrates how to connect and use the DCM series of Liquid Crystal Displays.
Introduction:
  The DCM series of Optrex Liquid Crystal Display (LCD) Modules are an easy to interface, low power method of providing a display on your project. Several display formats are available ranging from 8 to 40 characters across and from 1 to 4 lines of text.

These LCD Module have an I/O Line saving feature called 4-bit mode, where an 8-bit data word can be transferred to the LCD Module using only 4 data lines.

In this application note, we will connect a DCM-16230 16 character by 2 row LCD to an OOPic and write a program with a Virtual Circuit to display a flashing message.

I/O connections:
  To save on I/O lines, the LCD module is set into 4 bit mode. In this mode, the LCD module only requires a total of 6 I/O lines, however, to do so, requires a series of setup control codes to be sent to the LCD module. These control codes can be found in the routine LCDSetup.
  The I/O lines are connected in 3 sets.
  1. A set of 4 I/O Lines for the data connected to I/O Lines 28-31.
  2. A single I/O Line for the data strobe connected to I/O Line 27.
  3. A singe I/O Line for the register select function of the LCD module connected to I/O Line 26.

The LCD Module has a R/W line, but for this project, it is tied to ground, because all we are going to do is write text to the LCD.

Also, the LCD Module has a contrast adjustment, but we have found that if you also tie that to ground, it works just fine.

The LCD module requires +5 Volts to operate and is connected to one of the Ground and +5 Volts connections on the OOPic.

  In order to write an 8-bit character to the LCD Module, the ASCII data must be presented on the data lines DB0-DB7 and a data strobe must be presented to the E line. The LCD Module also has a 4-bit mode which only uses 4 data lines. In this mode, the 8-bit ASCII data is split into 2 nibbles which are sequentially presented to Data lines DB4-DB7 each with its own data strobe being presented to the E line. In either mode, the RS line is used to select which register within the LCD Module the data will be going to. When the RS line is 0, the data is sent to a Control-Register. And when the RS line is 1, the data is sent to the display screen.

To connect the LCD to the OOPic, 3 Hardware Objects must be created to manage the LCD's 3 I/O line connections.

Dim D As New oDio4 'Initializes a new object called D as a nibble I/O

Dim E As New oDio1 'Initializes a new object called E as a single bit I/O 

Dim RS As New oDio1 'Initializes a new object called RS as a single bit I/O 

These hardware object will be set up in the following manner.

D.IOGroup = 3    'I/O group used for nibble out to LCD 

D.Nibble = 1     'Which nibble to use Upper or Lower 

D.Direction = 0  'Direction of data flow in or out 
E.IOLine = 27    'Which I/O line to use for Display enable and strobe 

E.Direction = 0  'Direction of data flow in or out 

E = 0            'Initialize E to 0
RS.IOLine = 26   'Which I/O line to use for Register Select 

RS.Direction = 0 'Direction of data flow in or out 

RS = 0           'Initialize RS to 0
Virtual Circuit:
  Both the 8-bit mode and the 4-bit mode procedures can be done with a Virtual Circuit consisting of only an oDataStrobe Object. The purpose of the oDataStrobe Object is to provide a data-strobe signal for each byte of information that is passed through it. The oDataStrobe Object handles the 4-bit mode by automatically splitting up the 8 bits into 2 nibbles and individually passing the two nibbles each with its own data-strobe signal.

To create an oDataStrobe Object, insert the line

Dim LCD As New oDataStrobe 'Initializes a new object called LCD as a Data Strobe

The link the oDataStrobe Object to the I/O lines, use the following lines.

LCD.Output.Link(D)   'Connect the datastrobe's data to the LCD's data I/O line

LCD.Strobe.Link(E)   'Connect the datastrobe's datastrobe to the LCD's E I/O line

LCD.Operate = cvTrue 'Turn the Datastrobe object on.

With this Virtual Circuit in place, any writes to the LCD.Value property will result in the data and a data-strobe to be sent to the LCD Module.

The Program:
'This program sets up a Virtual Circuit to handle all of the data strobe function.
'Once all the setup have been done, all that is needed to write text to the LCD is 
'to execute a command like;
'  LCD.String = "TextToWrite" 
'-or- 
'  LCD.String = Str$(12345) 
'Note: This program used the String Basic Version of the OOPic compiler which also.

Dim D As New oDio4 'Initializes a new object called D as a nibble I/O
Dim E As New oDio1 'Initializes a new object called E as a single bit I/O 
Dim RS As New oDio1 'Initializes a new object called RS as a single bit I/O 
Dim LCD as New oDataStrobe 'Initializes a new object called LCD as a Data Strobe
dim x as new obyte

Sub main()
  'Start of main program
  Call IOSetup        'Calls sub program IOSetup 
  Call LCDSetup       'Calls sub program LCDSetup 
  do
    call ClearLCD
    call LocateRow1
    LCD.String = "Testing" 'Write text to the LCD
    for x = 1 to 50:next x
    call ClearLCD
    call LocateRow2
    LCD.String = "Testing" 'Write text to the LCD
    for x = 1 to 50:next x
  loop
End Sub 'End of main program

Sub LocateRow1() 
  'Routine to locate the cursor at row 1, column 1
  RS = 0           'Sets Register Select to Control Register
  LCD.Value = 128: 'Sets the address of the cursor
  RS = 1           'Sets Register Select to Data Register 
End Sub

Sub LocateRow2() 
  'Routine to locate the cursor at row 2, column 1
  RS = 0           'Sets Register Select to Control Register
  LCD.Value = 192: 'Sets the address of the cursor
  RS = 1           'Sets Register Select to Data Register 
End Sub

Sub ClearLCD() 
  RS = 0         'Sets Register Select to Control Register
  LCD.Value = 1: 'Sets the address of the cursor
  RS = 1         'Sets Register Select to Data Register 
End Sub

Sub IOSetup() 
  'This routine sets the IO lines that are connected to the LCD display
  'and configures the Virtual Circuit to do the Data Strobe.
  D.Iogroup = 3        'I/O group used for nibble out to LCD 
  D.Nibble = 1         'Which nibble to use Upper or Lower 
  D.Direction = 0      'Direction of data flow in or out 
  E.IOLine = 27        'Which I/O line to use for Display enable and strobe 
  E.Direction = 0      'Direction of data flow in or out 
  E = 0                'Initialize E to 0 
  RS.IOLine = 26       'Which I/O line to use for Register Select 
  RS.Direction = 0     'Direction of data flow in or out 
  RS = 0               'Initialize RS to 0
  LCD.Output.Link(D)   'Connect the datastrobe's data to the LCD's data I/O line
  LCD.Strobe.Link(E)   'Connect the datastrobe's datastrobe to the LCD's E I/O line
  LCD.Operate = cvTrue ' Turn the Datastrobe object on.
End Sub

Sub LCDSetup() 
  'This routine performs LCD reset and initialization and 
  'configures LCD display to operate in 4 bit nibble mode 
  'Note: LCD Module starts out in 8 bit mode'
  'This sequence of codes were found in the Optrix handbook.
  RS = 0 'Sets Register Select to Control Register
  LCD.Mode = cv8Bit: 'Select 8-bit mode
  LCD.Value = 3:     ' Power on sequence
  LCD.Value = 3:     ' Power on sequence
  LCD.Value = 3:     ' Power on sequence
  LCD.Value = 2:     ' Sets data length to 4 bits 
  LCD.Mode = cv4Bit: 'Select 4-bit mode
  LCD.Value = 40:    ' Set # of display lines & font 
  LCD.Value = 8:     ' Set display off 
  LCD.Value = 12:    ' sets display on 
  LCD.Value = 6:     ' Set entry mode 
  RS = 1 'Sets Register Select to Data Register 
End Sub

    Send mail and comments to: Savage Innovations.