The HD44780 is a commenly used LCD controller that can be found on many alphanumeric LCD's. Most of them have one or 2 lines and 16 or 20 characters per line. These LCD's can be bought on ebay for just a few dollars and are available in a wide range of background and character colors.The library is made by a Simplecortex user, the original forum thread can be found here. The library and example can be found in our repository.
To begin it is needed to include the libraries. This is done by these commands:
The libraries for the microcontroller itself and the variables have to be included to:
3. initialize the LCD
First the LCD should be initialised correctly. To do this the command init_lcd(); is used. This will initialise the LCD as an 2 line LCD. By default the LCD is connected to the Simplecortex like this:
* ---LCD--- --SimpleCortex--
* (2)VCC 5V
* (1)GND gnd
* (4)RS p2.3
* (5)RW p2.4
* (6)EN p2.5
* (11)DB4 p0.4
* (12)DB5 p0.5
* (13)DB6 p0.6
* (14)DB7 p0.7
To change this the lcd44780.h file should be altered. In this file the following lines can be found:
#define LCDGPIO LPC_GPIO2 //Change this to change the gpio IO port
#define LCDDATA LPC_GPIO0 //Change this to change the data IO port
By default all the data pins use GPIO port 0.x and all IO pins use GPIO port 2.x, By changing LPC_GPIOX this can be altered.
To change the GPIO pins used the following lines has to be altered:
#define LCDRS (1 << 3) //Change this to change the RS data pin
#define LCDRW (1 << 4) //Change this to change the RW data pin
#define LCDEN (1 << 5) //Change this to change the EN data pin
#define LCD_D4 (1 << 4) //Change this to change the D4 gpio pin
#define LCD_D5 (1 << 5) //Change this to change the D5 gpio pin
#define LCD_D6 (1 << 6) //Change this to change the D6 gpio pin
#define LCD_D7 (1 << 7) //Change this to change the D7 gpio pin
(1 << 3) means that GPIO pin 3 is used for the LCD pin, the RS pin uses pin 3 and port 2 by default, P2.3.
4. Send data to the LCD
There are a couple ways to put data on the LCD. To send one character to the LCD the command lcd_putchar(char); is used. To send the letter A to the LCD:
Normally the letter A will now appear on the first line as the first character. To place the character somewhere else the command lcd_gotoxy(line, char); is used.
This command places the cursor to a specific line and place, to place it on the second line and the sixst place the command is:
Any characters placed now will appear on that place.
The last option is to place a string on the LCD. To do this the command lcd_putstring(line, string); is used. To display "Hello world" on the first line the command is:
And very important, to clear the LCD the command lcd_clear(); is used. This clears the LCD and puts the cursus back at line 0 char 0.