Hi,
I have a simple project that talks to the Sparkfun serial LCD board. Here it is, so enjoy. This was built off the LCD project here, with a few changes. Not all of the fuctions are working just yet, as it appears that the LCD needs a few commands added.
Bob
// *
// * ------------
// * Control a Serial LCD Display
// *
// * Tested on a Matrix Orbital model LCD0821 display.
// * Other diplays will work but may have slightly different
// * command codes and hardware setups.
// *
// * Copyleft 2006 by djmatic
// *
// * More copyleft 2007 Bob Grabau
// * ------------
// *
// *
// Definitions for the SparkFun SerLCD version 2 code.
#define BLINK_ON 0x0d
#define BLINK_OFF 0x0c
#define DISPLAY_ON 0x0c
#define DISPLAY_OFF 0x08
#define SHIFT_RIGHT 0x1c
#define SHIFT_LEFT 0x18
#define BACKLIGHT_OFF 128
#define BACKLIGHT_40 140
#define BACKLIGHT_70 150
#define BACKLIGHT_FULL 157
// Declare your program variables here
// Arduino and LCD setup
void setup()
{
// Communication to the Serial LCD display is defaulted to 9600 baud.
beginSerial(9600);
}
// MAIN CODE
void loop()
{
clearLCD();
Serial.print(" Hello Arduino"); // print text to the current cursor position
newLine(); // start a new line
Serial.print("Frm SparkFun V2");
cursorOn();
delay(5000);
cursorHome();
delay(5000);
cursor(BLINK_ON);
delay(5000);
cursor(BLINK_OFF);
cursorOff();
delay(5000);
cursor(DISPLAY_OFF);
delay(5000);
cursor(DISPLAY_ON);
delay(5000);
cursor(SHIFT_RIGHT);
delay(5000);
cursor(SHIFT_LEFT);
delay(5000);
Set_Backlight(BACKLIGHT_OFF);
delay(1000);
Set_Backlight(BACKLIGHT_40);
delay(1000);
Set_Backlight(BACKLIGHT_70);
delay(1000);
Set_Backlight(BACKLIGHT_FULL);
delay(5000);
}
// LCD FUNCTIONS-- keep the ones you need.
// clear the LCD
void clearLCD()
{
Serial.print(254, BYTE);
Serial.print(1, BYTE);
}
// start a new line
void newLine()
{
Serial.print(254, BYTE);
Serial.print(0xC0, BYTE);
}
// general cursor / display command routine
void cursor(int Mode)
{
Serial.print(254, BYTE);
Serial.print(Mode, BYTE);
}
// move the cursor to the home position
void cursorHome()
{
Serial.print(254, BYTE);
Serial.print(2, BYTE);
}
// turn the cursor on
void cursorOn()
{
Serial.print(254, BYTE);
Serial.print(0x0E, BYTE);
}
// turn the coursor off
void cursorOff()
{
Serial.print(254, BYTE);
Serial.print(0x0C, BYTE);
}
// move the cursor to a specific place
// e.g.: cursorSet(3,2) sets the cursor to x = 3 and y = 2
void cursorSet(int xpos, int ypos)
{
#define HSIZE 16
#define VSIZE 2
int pos;
pos = (ypos * HSIZE) + xpos;
pos += 0x80;
// cur pos still broken
Serial.print(pos, HEX);
Serial.print(254, BYTE);
Serial.print(pos, BYTE);
}
// backspace and erase previous character
void backSpace()
{
// Serial.print(8, BYTE);
}
// move cursor left
void cursorLeft()
{
// Serial.print(254, BYTE);
// Serial.print(76, BYTE);
}
// move cursor right
void cursorRight()
{
// Serial.print(254, BYTE);
// Serial.print(77, BYTE);
}
// set LCD contrast
void setContrast(int contrast)
{
// Serial.print(254, BYTE);
// Serial.print(80, BYTE);
// Serial.print(contrast);
}
// turn on backlight
void backlightOn(int minutes)
{
// Serial.print(254, BYTE);
// Serial.print(66, BYTE);
// Serial.print(minutes); // use 0 minutes to turn the backlight on indefinitely
}
// Set the backlight by value
void Set_Backlight(int val)
{
Serial.print(124, BYTE);
Serial.print(val, BYTE);
}