From 06e9aec1e01e6c18e0381d20be20584102f7e6dd Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 19 Jun 2009 03:04:34 +0000 Subject: [PATCH] seems to be working better with a full initialization routine git-svn-id: svn://anubis/misc/parport-2x20vfd@116 bd8a9e45-a331-0410-811e-c64571078777 --- VFD.cc | 33 +++++++++++++++++++++++---------- VFD.h | 3 ++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/VFD.cc b/VFD.cc index 7748566..9aacecd 100644 --- a/VFD.cc +++ b/VFD.cc @@ -1,5 +1,5 @@ -/* +/* * Author: Josh Holtrop * Date: 2009-05-03 * See VFD.h for documentation @@ -56,8 +56,28 @@ bool VFD::connect(const std::string & parport) else { usleep(INIT_DELAY); + + sendNibble(0, 0x8); /* set 8-bit mode (sync) */ + sendNibble(0, 0x8); /* set 8-bit mode (sync) */ + sendNibble(0, 0x8); /* set 8-bit mode (sync) */ + sendNibble(0, 0x2); /* set 4-bit mode */ + sendByte(1, 0); /* set brightness */ + usleep(2); + + sendByte(0, 0x8); + usleep(2); + + sendByte(0, 0x1); + usleep(DISPLAY_CLEAR_DELAY); + + sendByte(0, 0x0C); + usleep(2); + + sendByte(0, 0x6); + usleep(2); + return true; } @@ -93,7 +113,7 @@ void VFD::sendNibble(unsigned char rs, unsigned char dat) | (E_DISABLE << PP_OFFSET_E) | (RW_WRITE << PP_OFFSET_RW) | ((dat & 0xF) << PP_OFFSET_DATA) ); - usleep(1); +// usleep(1000); setPPLines( (rs << PP_OFFSET_RS) | (E_ENABLE << PP_OFFSET_E) | (RW_WRITE << PP_OFFSET_RW) @@ -104,13 +124,6 @@ void VFD::sendNibble(unsigned char rs, unsigned char dat) | (RW_WRITE << PP_OFFSET_RW) | ((dat & 0xF) << PP_OFFSET_DATA) ); usleep(1); -#if 0 - setPPLines( (rs << PP_OFFSET_RS) - | (E_DISABLE << PP_OFFSET_E) - | (RW_WRITE << PP_OFFSET_RW) - | ((dat & 0xF) << PP_OFFSET_DATA) ); - usleep(1000); -#endif } void VFD::sendByte(unsigned char rs, unsigned char dat) @@ -122,7 +135,7 @@ void VFD::sendByte(unsigned char rs, unsigned char dat) void VFD::displayClear() { sendByte(0, 0x1); - usleep(INIT_DELAY); + usleep(DISPLAY_CLEAR_DELAY); } void VFD::cursorHome() diff --git a/VFD.h b/VFD.h index c7e2ef2..74682e8 100644 --- a/VFD.h +++ b/VFD.h @@ -71,7 +71,8 @@ class VFD static const unsigned char PP_OFFSET_RW = 1; static const unsigned char PP_OFFSET_E = 2; static const unsigned char PP_OFFSET_DATA = 3; - static const int INIT_DELAY = 10000; + static const int INIT_DELAY = 10 * 1000; + static const int DISPLAY_CLEAR_DELAY = 2300; void sendByte(unsigned char rs, unsigned char dat); void sendNibble(unsigned char rs, unsigned char dat);