Code Module #2 - LCD Interface

EMICROS - Embedded Micro Software, Last Update: 11/08/08

Introduction
A liquid-crystal-display (LCD) is a simple and inexpensive device used to display information and prompt the user for information. LCD modules with 1 to 4 lines (or rows) and widths from 8 to 20 characters are common and offered from a variety of manufacturers. The 8-bit command and data interface between these modules are the same but refer to the specification if there is any doubt.

The software detailed for the CANTEC11 is designed and tested using a 4 line by 16 character display from Optrex, part # DMC16433. Digikey has this display (DMC-16433N-B) in High Contrast Supertwist format for about $29.

Functions required to control the LCD are as follows;

  • Write Command/Data to LCD
  • Modify putc() to interface to CANTEC11 LCD
  • Initialize LCD Module
  • Display string and data using printf()

For reference purposes, print the lcd.c, lcd.h, iochar.c, cm2.c, and vectors.c.

Write Command/Data to LCD
The LCD is controlled by writing 8-bit commands and data to it. The LCD enable signal is active high and generated by decoding address lines A15, A14, A13, and A12. Address line A0 is connected to the command/data line.

Commands to the LCD use address $4000 and data to the LCD use address $4001. The
#define _LCD_BASE 0x4000 sets the base address of the LCD for the CANTEC11 board, the #define LCDcmmd *(unsigned char volatile *)(_LCD_BASE+0x00) sets the command address. #define LCDdata *(unsigned char volatile *)(_LCD_BASE+0x01) sets the data address. The statement LCDcmmd = 0x38; writes a command and LCDdata = 1; writes data.

Modify putc() to interface to CANTEC11 LCD
'C' uses the putchar() as the low-level function to write a character to the display device. ICC11 includes the file iochar.c which uses the serial port as the display device and must be modified to interface to the CANTEC11 LCD.

The modified iochar.c file must be compiled and placed in the library file using the following;

icc11 -c iochar.c
ilib -a libc11.a iochar.o

Initialize LCD Module
The LCD module must be intialized before it can display information. The Optrex data sheet defines the initialization sequence that is executed in the InitLCD() function. The 10 millisecond delay times are not the optimum value and could be reduced for time critical application. Before InitLCD() is executed in lesson2.c, a 15 millisecond delay is executed. This is also recommended in the data sheet. InitLCD() is in the lcd.c file and the C prototype is in the lcd.h.
Display string and data using printf()
The main() function that puts this all together is in file cm2.c. The program;
  1. Intializes the LCD
  2. Prints an opening message
  3. Delays 2 seconds
  4. Clears the display
  5. Then prints a variable that increments every 250 milliseconds.

To compile the files, use the following statements;

set ICC11_LINKER_OPTS=-btext:0xe000 -bdata:0x6000 -dinit_sp:0x7fff -dheap_size:0
icc11 cm2.c lcd.c delay.s

Last Update: 11/08/08