The HD44780 based displays are parallel devices.

Below is an example on using these displays with a Parallax Javelin Stamp. The Program displays a message and a custom character on the LCD.

The program uses a class file I created for the HD44780 chipset. The class file is my first major attempt at seriously programming in Java. It supports the basic functions of the HD44780:

More functions will be added later. (Move cursor to X, shift display, etc.).

Having learnt a little c++ last semester at University, Java has a few differences that got me stuck for a while (eg: What the heck is a final static char????) - but a read of the manual sorted it out (final = "this is a constant"). :-)

Connect the LCD to the Javelin as follows:

The main program:

import stamp.core.*; //import = #include in c++
import stamp.peripheral.io.parallellcd.*;
//path to where I stored my hd44780 class file

public class parallelLCDtest
{
//declare global constant (final means constant)
final static char[] smiley = {0x00, 0x0A, 0x0A, 0x00, 0x11, 0x0E, 0x06, 0x00};
//custom character

public static void main()
{
hd44780 LCD = new hd44780();
LCD.initialisedisplay();
LCD.downloadcustomcharacter(1, smiley);
//download custom char to address 1
LCD.cleardisplay();
LCD.displaystring("Javelin Stamp");
LCD.newline();
LCD.displaystring("Pro IDE Board ");
LCD.displaystring(0x01);
//display the custom character we loaded in to address 1 also shows overloading - we are calling the same function but sending it an integer this time.
}
}

 

The following example gets a little more complex. It downloads a few more custom characters, and gives a Pacman style effect for animation.

import stamp.core.*;
import stamp.peripheral.io.parallellcd.*;

public class parallelLCDtest
{
//declare global constant (final means constant)
final static char[] smiley = {0x00, 0x0A, 0x0A, 0x00, 0x11, 0x0E, 0x06, 0x00};
final static char[] pacman1 = {0x0E, 0x1F, 0x1C, 0x18, 0x1C, 0x1F, 0x0E, 0x00};
final static char[] pacman2 = {0x0E, 0x1F, 0x1F, 0x18, 0x1F, 0x1F, 0x0E, 0x00};
final static char[] pacman3 = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x00};

static hd44780 LCD = new hd44780();

public static void main()
{
LCD.initialisedisplay();
LCD.downloadcustomcharacter(0, smiley);
//download custom char to address 1
LCD.downloadcustomcharacter(1, pacman1);
//download custom char to address 2
LCD.downloadcustomcharacter(2, pacman2);
//download custom char to address 3
LCD.downloadcustomcharacter(3, pacman3);
//download custom char to address 4

while(true)
{
LCD.cleardisplay();
LCD.displaystring(" LENNARD ");
LCD.newline();
LCD.displaystring(" ELECTRONICS ");
CPU.delay(20000);
// start the animation
LCD.cleardisplay();
LCD.displaystring("Javelin Stamp ");
doanimation("Pro IDE Board ");
}
}

static void doanimation(String strings)
{
for (int i = 0; i < strings.length(); i++)
{
//first, draw pacman1,2,3, then the actual character
for (int j = 1; j < 4; j++)
{
CPU.writePort(CPU.PORTA, (byte) j);
CPU.pulseOut(1000,CPU.pin8);
CPU.delay(2000);
LCD.placecursor(0x40 + i);
}
CPU.writePort(CPU.PORTA, (byte)(strings.charAt(i)));
CPU.pulseOut(1000,CPU.pin8);
}
LCD.placecursor(0x4f);
LCD.displaystring(0x00);
CPU.delay(20000);
}
}

My HD44780 class file:

package stamp.peripheral.io.parallellcd;

import stamp.core.*;
/* Class to interface to HD44780 based parallel displays */
//created 12/12/2003
// version 1: PORTA = data0 to 7 - 8 bit mode only supported.
//15/12/2003
// version 1.01: Moved port output initialisation to the constructor, added cursor placement
//6/1/2004
//version 1.02: Moved initialisation code to the constructor
// pin8 = E
//pin 9 = RW
//pin 10 = RS
//Future version: allow user to allocate whatever pins they like

//Default initialisation is 8 bit mode, 2 lines, no cursor

public class hd44780
{
private int port;
private int RS;
private int RW;
private int E;

//constructor
public hd44780()
{
//set all PORTS as an output - setting pin10 false sets up LCD for sending an instruction
CPU.writePin(CPU.pin0 + CPU.pin1 + CPU.pin2 + CPU.pin3 + CPU.pin4 + CPU.pin5 + CPU.pin6 + CPU.pin7, false);
CPU.writePin(CPU.pin8 + CPU.pin9 + CPU.pin10, false);
//Initialise the display with the following 3 commands
//Set display to 8 bit mode, and 2 lines, default font

LCDcommand(0x38);
//Turn the display off
LCDcommand(0x08);
//Turn the display on, without a cursor
LCDcommand(0x0C);
}

public void turnoncursor()
{
LCDcommand(0x0F);
}

public void turnoffcursor()
{
LCDcommand(0x0C);
}

public void cleardisplay()
{
LCDcommand(0x01);
}

public void downloadcustomcharacter(int CGRAMaddress, char character[])
{
LCDcommand(0x40 + (8 * CGRAMaddress));
for (int i = 0; i<8; i++)
//load character bytes in to CGRAM
{
displaystring(character[i]);
}
}

public void newline()
{
LCDcommand(0xC0);
}

public void displaystring(int character)
{
CPU.writePort(CPU.PORTA, (byte) character);
CPU.pulseOut(500,CPU.pin8);
}

public void displaystring(String strings)
{
for (int i = 0; i < strings.length(); i++)
{
CPU.writePort(CPU.PORTA, (byte)(strings.charAt(i)));
CPU.pulseOut(500,CPU.pin8);
}
}

public void placecursor(int place)
{
LCDcommand(0x80 + place);
}

private void LCDcommand(int command)
{
CPU.writePin(CPU.pin10, false);
CPU.writePort(CPU.PORTA, (byte) command);
CPU.pulseOut(500,CPU.pin8);
CPU.writePin(CPU.pin10, true);
}
}