LCD Overview

Introduction:

The LCD routines in this section allow GCBASIC programs to control an alphanumeric Liquid Crystal Displays based on the HD44780 IC. This covers most 16 x 1, 16 x 2, 20 x 4 and 40 x 4 LCD displays.

The GCBASIC methods allow the displays to be connected to the microcontroller

Connection Modes:

The table below shows the connection modes. These modes support the connection to the LCD using differing methods.

Connection Mode Required Connections

0

No configuration is required directly by this method. The LCD routines must be provided with other subroutines which will handle the communication. This is useful for communicating with LCDs connected through RS232 or I2C.
This is an advanced method of driving an LCD.

1

Uses a combined data and clock line. This mode is used when the LCD is connected through a shift register 74HC595, as detailed at here.
This method of driving an LCD requires an additional integrated circuit and other passive components. This is not recommended for the beginner.

2

Uses separated Data and Clock lines. This mode is used when the LCD is connected through a 74LS174 shift register IC, as detailed at here
This method of driving an LCD requires additional integrated circuits and other passive components. This is not recommended for the beginner.

3

DB, CB, EB are connected to the microcontroller as the Data, Clock and Enable Bits.
This a common method to connect a microcontroller to an LCD. This requires 3 data ports on the microcontroller.

4

R/W, RS, Enable and the highest 4 data lines (DB4 through DB7) are connected to the microcontroller. The use of the R/W line is optional.
This a common method to connect a microcontroller to an LCD. This requires 7(6) data ports on the microcontroller.

8

R/W, RS, Enable and all 8 data lines. The data lines must all be connected to the same I/O port, in sequential order. For example, DB0 to PORTB.0, DB1 to PORTB.1 and so on, with`DB7` going to PORTB.7.
This is a common method to connect a microcontroller to a LCD. This requires 11(10) data ports on the microcontroller.

10

The LCD is controlled via I2C. A type 10 LCD 12C adapter. Set LCD_IO to 10 for the YwRobot LCD1602 IIC V1 or the Sainsmart LCD_PIC I2C adapter
This is a common method and requires two data ports on the microcontroller.

12

The LCD is controlled via I2C. A type 12 LCD 12C adapter. Set LCD_IO to `12`for the Ywmjkdz I2C adapter with a potentiometer (variable resistance) bent over top of chip.
This is a common method and requires two data ports on the microcontroller.

107

The LCD is controlled via serial. Set LCD_IO to 107 or K107.
The K107 requires one serial data ports on the microcontroller.



Supported LCDs mapped to Connection Mode

The support of various types of LCD displays are shown in the following table.

Supported LCD Type
number of characters x number of lines
Connection Mode

16 x 1, 16 x 2, 20 x 2, 20 x 4 type LCD displays,
also known as 1601, 1602, 2002, 2004 type LCD displays.

0,1,2,4,8,10 and 12

40 x 4 LCD displays,
also known as 4004 type LCD displays.

4

16 x 1 LCD displays, with a non-standard/non-consective memory map.

This LCD sub type is supported using a specific constant.

Use #define LCD_VARIANT 1601a to use this sub variant.

Also known as 1601 type LCD displays.

Supports any LCD_IO mode.

Communication Performance

There may be a need to change the communication performance for a specific LCD as some LCD’s are slower to operate. GCBASIC supports change the communications speed.

To change the performance (communications speed) of the LCD use #DEFINE LCD_SPEED. This method allows the timing to be optimised.

Example

 #DEFINE LCD_SPEED  FAST
Define Performance Characteristics

LCD_SPEED

FAST - The speed is approximately 20,000 CPS.
MEDIUM - The speed is approximately 15,000 CPS.
SLOW - The speed is approximately 10,000 CPS.
OPTIMAL - The speed is approximately 30,000 CPS.

If LCD_SPEED is not defined, the speed defaults to SLOW

     

Using LCD_Speed OPTIMAL
  

Note

   OPTIMAL disables fixed delays and allows the LCD operate as fast as it can.  In this mode, The the busy flag is polled before each byte is sent to the HD44780 controller.   This not only optimizes speed, but also assures that data is not sent to the diplay controler until it is ready to receive the data.

With most displays this equates to a speed of about 30,000 characters per second.  For comparision about 10 times faster than I2C using a PC8574 Expander (See LCD_IO 10 or See LCD_IO 112)

OPTIMAL is only supported in LCD_IO 4,8 and only when LCD_NO_RW is not defined (RW Mode).  When #DEFINE LCD_NO_RW is defined, reading data from the HD44780 is not possible since this disables Read Mode on the controller.  In this case busy flag checking is not available and the GET subroutine is not avaiable.

In order to enable busy flag checking, and, therefore to use the GET command the following criteria must be true.

  1. LCD I/O Mode must be either 4-wire or 8-wire
  2. #DEFINE LCD_NO_RW is not defined
  3. An I\O pin is connected between the microcontroller and the RW connection on the LCD Display
  4. 'DEFINE LCD_RW port.pin is defined in the GCBASIC source code

Example:

  #DEFINE LCD_IO 4
  #DEFINE LCD_SPEED OPTIMAL

  #DEFINE LCD_DB7 PORTB.5
  #DEFINE LCD_DB6 PORTB.4
  #DEFINE LCD_DB5 PORTB.3
  #DEFINE LCD_DB4 PORTB.2

  #DEFINE LCD_RW PORTA.3    'Must be defined for RW Mode
  #DEFINE LCD_RS PORTA.2
  #DEFINE LCD_ENABLE PORTA.1

Changing the LCD Width

To change the LCD width characteristics use #define LCD_WIDTH



See the separate sections of the Help file for the specifics of each Connection Mode.

For more help, see LCD_IO 0, LCD_IO 1, LCD_IO 2, LCD_IO 3, LCD_IO_2 74xx164, LCD_IO_2 74xx174, LCD_IO 4, LCD_IO 8, LCD_IO 10 or LCD_IO 12

and,

LCD_Width, LCD_Speed