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.
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 (
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.
Send on character (one byte) to be displayed at current cursor position. Cursor will then be increased by 1.
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.
Print an integer value at current cursor position. Values are
int type and range from 0 to 65535.
Print an large integer value at current cursor position. Values are
long type and range from 0 to 4294967295.
Print a value in hex format at current cursor position. Hex values are 8 bit, 16 bit and 32 bit respectively.
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
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.
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.
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.