From 14214f7a9973f5fb7b3349ae770288a50f2e5bac Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 4 May 2009 01:50:07 +0000 Subject: [PATCH] display not working again, need more investigation into why it stopped :( git-svn-id: svn://anubis/misc/parport-2x20vfd@115 bd8a9e45-a331-0410-811e-c64571078777 --- Makefile | 5 +++-- VFD.cc | 21 ++++++++++++++------- VFD.h | 10 +++++----- driver.cc | 15 ++++++++++++--- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 6870ff7..dcfe51e 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ TARGET := driver SRCS := $(wildcard *.cc) +HEADERS := $(wildcard *.h) all: $(TARGET) -$(TARGET): $(SRCS) - $(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $^ +$(TARGET): $(SRCS) $(HEADERS) + $(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $(SRCS) diff --git a/VFD.cc b/VFD.cc index 4dafd2d..7748566 100644 --- a/VFD.cc +++ b/VFD.cc @@ -89,11 +89,6 @@ void VFD::setPPLines(unsigned char bits) void VFD::sendNibble(unsigned char rs, unsigned char dat) { - setPPLines( (rs << PP_OFFSET_RS) - | (E_ENABLE << PP_OFFSET_E) - | (RW_WRITE << PP_OFFSET_RW) - | ((dat & 0xF) << PP_OFFSET_DATA) ); - usleep(1); setPPLines( (rs << PP_OFFSET_RS) | (E_DISABLE << PP_OFFSET_E) | (RW_WRITE << PP_OFFSET_RW) @@ -104,6 +99,18 @@ void VFD::sendNibble(unsigned char rs, unsigned char dat) | (RW_WRITE << PP_OFFSET_RW) | ((dat & 0xF) << PP_OFFSET_DATA) ); usleep(1); + setPPLines( (rs << PP_OFFSET_RS) + | (E_DISABLE << PP_OFFSET_E) + | (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) @@ -159,7 +166,7 @@ void VFD::setAddress(unsigned char address) sendByte(0, 0x80 | (address & 0x7F)); } -void VFD::writeData(unsigned char data) +void VFD::writeByte(unsigned char data) { sendByte(1, data); } @@ -168,6 +175,6 @@ void VFD::write(const std::string & str) { for (const char * chr = str.c_str(); *chr; chr++) { - writeData(*chr); + writeByte(*chr); } } diff --git a/VFD.h b/VFD.h index 2a0211d..c7e2ef2 100644 --- a/VFD.h +++ b/VFD.h @@ -38,8 +38,8 @@ class VFD static const unsigned char RIGHT = 1; static const unsigned char OFF = 0; static const unsigned char ON = 1; - static const unsigned char ADDRESS_LINE1 = 0x80; - static const unsigned char ADDRESS_LINE2 = 0xC0; + static const unsigned char ADDRESS_LINE1 = 0x00; + static const unsigned char ADDRESS_LINE2 = 0x40; VFD(); ~VFD(); @@ -57,14 +57,14 @@ class VFD unsigned char direction); /* LEFT|RIGHT */ void setCGAddress(unsigned char address); void setAddress(unsigned char address); - void writeData(unsigned char data); + void writeByte(unsigned char data); void write(const std::string & str); protected: static const unsigned char RW_WRITE = 0; static const unsigned char RW_READ = 1; - static const unsigned char E_ENABLE = 0; - static const unsigned char E_DISABLE = 1; + static const unsigned char E_DISABLE = 0; + static const unsigned char E_ENABLE = 1; static const unsigned char RS_COMMAND = 0; static const unsigned char RS_DATA = 1; static const unsigned char PP_OFFSET_RS = 0; diff --git a/driver.cc b/driver.cc index 189ed64..a76f747 100644 --- a/driver.cc +++ b/driver.cc @@ -6,14 +6,23 @@ using namespace std; int main(int argc, char ** argv) { - cout << "Working on VFD module" << endl; - VFD vfd; vfd.connect(); vfd.setDisplay(1, 0, 0); + vfd.displayClear(); + vfd.setAddress(VFD::ADDRESS_LINE1); - vfd.write("Hi there!"); + for (int i = 1; i < argc; i++) + { + for (const char * chr = argv[i]; *chr; chr++) + { + if (*chr == '\n') + vfd.setAddress(VFD::ADDRESS_LINE2); + vfd.writeByte(*chr); + } + } + vfd.disconnect(); return 0;