Monday 6 July 2009

ByVac Serial LCD displays

I bought a nice 4x20 LCD display on eBay which had a Serial LCD Controller made (or distributed) by ByVac. There were some teething troubles (mostly to do with timing), but managed to get it working nicely in the end. If you happen to get one on ebay or something, then feel free to use this code for arduino:

#include "NewSoftSerial.h"
#define lcdTxPin 6

#define lcdRxPin 5 //we ignore what the LCD tells us
#define LCD_LINE1 0x80

#define LCD_LINE2 0xC0
#define LCD_LINE3 0x94
#define LCD_LINE4 0xD4
#define LCD_SET_LINE1 "ac80\r"
#define LCD_SET_LINE2 "acc0\r"
#define LCD_SET_LINE3 "ac94\r"
#define LCD_SET_LINE4 "acd4\r"
#define LCD_BACKLIGHT_ON "ab1\r"
#define LCD_BACKLIGHT_OFF "ab0\r"
#define LCD_HIDE_DISPLAY "ac08\r"
#define LCD_SHOW_DISPLAY "ac0C\r"
#define LCD_MOVE_CURSOR_LEFT "ac10\r"
#define LCD_MOVE_CURSOR_RIGHT "ac14\r"
#define LCD_SHOW_BLINKING_CURSOR "ac0F\r"
#define LCD_SHOW_UNDERLINE_CURSOR "ac0E\r"
#define LCD_HOME "ac02\r"
#define LCD_CLEAR_SCREEN "ac01\r"
#define LCD_HIDE_CURSOR "ac0C\r"
#define LCD_SCROLL_LEFT "ac18\r"
#define LCD_SCROLL_RIGHT "ac1E\r"

NewSoftSerial softSerial = NewSoftSerial(lcdRxPin,lcdTxPin);


void setup()
{
softSerial.begin(9600);
pinMode(lcdTxPin,OUTPUT);
pinMode(lcdRxPin,INPUT);

LCDInit();

LCDCommand(LCD_CLEAR_SCREEN);
LCDCommand(LCD_HOME);
LCDWrite("Hello World");
}

void loop()
{
}

void LCDInit()
{
softSerial.print('\r');
delay(50);
softSerial.print('\r');
delay(50);
softSerial.print('\r');
delay(50);
}

void LCDSetCursorPos(int line, int pos)
{
//set the cursor pos - combine line and pos
softSerial.print("ac");
softSerial.print(line+pos,HEX);
softSerial.print("\r");
delay(10);
}

void LCDWrite(char* s)
{
softSerial.print("at'");
softSerial.print(s);
softSerial.print("'\r");
delay(5);
}

void LCDCommand(char* command)
{
softSerial.print(command);
delay(5);
}

No comments:

Post a Comment