Character LCD (cLCD) Library

1. Introduction

cLCD library provides ready to use functions to control common character LCD modules. Many LCD modules with different sizes, colors and character configurations are compatible with the library. For instance, cLCD library can work with 2x16 (2 lines 16 characters per line), 2x20, 4x20, 2x40 and the little one 2x8 LCD modules.

2. Use

cLCD library requires 6 I/O pins to control the LCD module and they can be any pin of Ansteron Board. LCD modules that have interface and command set compatible with HD44780 driver chip will work with the library. Most of the time, there is a 16 pin connector on the module, those are signal lines. The name and function of each pin is described in the datasheet or similar to the on in circuit below. Besides, one 10K potentiometer is needed to adjust contrast level of the LCD module. Below is the connection to a typical LCD module but it works for most modules as well.

In the circuit, there are 2 control lines E and RS and 4 data lines, D4 through D7. These signal lines can connect to any I/O pin of Ansteron Board. They do not necessarily to be the same as the above circuit. The potentiometer is there to control contrast level of the LCD. It acts as a voltage divider and its output is connected to pin Vo (pin number 3) of the LCD module. Pin number 5 of the LCD (R/W) must be connected to GND since data will only be written. Power supply for all logic functions of the module is from pin 1 and 2 (Vss is connected to GND and Vdd is connected to +5V pin of Ansteron Board).

Note: Supply voltage for backlight should not connect to +5V pin of Ansteron Board when using USB as power source. The backlight could draw 280mA or more and that will make the voltage drop below 4.5V. Logic functions of the LCD module may not work properly if voltage supply goes low.

The example program below will initialize the LCD module and write a test message on to the first line. If all signal lines are connected correctly, the message will show up. The potentiometer that controls contrast may also need to be adjusted for the text to be visible.

3. Functions

All functions of cLCD library starts with "cLCD_" prefix to be distinguished to other libraries. To include cLCD library with the program, in Ansteron IDE, go to menu build then select Compiler setting. In the dialog, add the library file to Additional libraries section.

cLCD_setup(RS_pin, E_pin, D4_pin, D5_pin, D6_pin, D7_pin);

This function will initialize the module. Other functions will not work before this function is called. Inputs of the function are the signal pins that LCD module is connected to (PIN_Bx, PIN_Cx, PIN_Dx).

cLCD_message(message);

Send a message to be displayed, starting at current cursor position. The cursor position will be increased by the number of characters of the message.

cLCD_send_char(data);

Send on character (one byte) to be displayed at current cursor position. Cursor will then be increased by 1.

cLCD_goto(line, position);

Move the cursor to given line and position. Line value can be 0, 1, 2 or 3. Position value can be any from 0 to 39. For LCD modules that have less than 40 characters in a line, enter position value larger than the actual character per line will may bring the cursor to next line or to non-visible position.

cLCD_print_int(value);

Print an integer value at current cursor position. Values are int type and range from 0 to 65535.

cLCD_print_long(value);

Print an large integer value at current cursor position. Values are long type and range from 0 to 4294967295.

cLCD_print_hex8(value);

cLCD_print_hex16(value);

cLCD_print_hex32(value);

Print a value in hex format at current cursor position. Hex values are 8 bit, 16 bit and 32 bit respectively.

cLCD_clear_display();

Make the entire display blank and the cursor return to the first position (line 0, character 0).

cLCD_blank(line, position, length);

Blank out by length number of characters starting at position given by line and position values. The cursor will then move to the position given by line and position.

cLCD_show_cursor(on_off);

Show the blinking cursor to indicate where its position on the display. Giving value 0 to will turn the cursor off and any value different than 0 will turn the cursor on.

cLCD_display_on(on_off);

Turn the logic functions of the display on or off. When turn the display off, the content stays the same. Giving value 0 will make the display off; non-zero will make the display on. Note that LCD backlight is not under control of logic functions.

_cLCD_send_command(command);

Send a low level command to LCD module. This function is intended for internal use; however, the program can use this to achieve full control of the LCD. Refer datasheet of the LCD module for the list of low level commands and their usage.

4. Example

In this example, the program will write an integer value to the LCD which will increase every 500 milliseconds. The value will automatically reset to 0 after it reaches 255 because it is one byte. The position where the value will lay is blanked out before the new value is updated. This will be faster than clear and redraw the entire display.

5. Note

These LCD modules are not designed for fast updating. The program should only update the characters that are needed instead of clearing the display and redraw. The update rate should be 10 times per second or less.

When using 5V power from +5V pins of Ansteron Board for the backlight of LCD module, a part of the board may get hot when external power supply is the power source. The hottest part is the voltage regulator sitting next to LED marked ON.