LCDWindow

Intro

This library is intened to

  • drive several LCD displays
  • at the same time (the same or different types)
  • allow creating windows on them (meaning frames were one can write into)
  • and combine these windows

This should make it easier to use larger displays that the normal 16x2 ones, when they are used to display several types of information at once.

It also is written in a manner that allows calling it from an interrupt as well as from thr main loop (using a semaphore).

LCD Types

  • HD44780 based, in 8bit mode
  • the DOGM16x series from Electronic assembly, in SPI mode (1-3 lines)
  • KS0108-based graphical displays (right now up to 128x64 pixels)
  • SED1335- based graphical displays (in text mode only)

Window types

  • each LCD display is seen as a single window
  • create (multiple)  sub windows of a window
  • combine multiple windows to a larger one (stacking them on top of each other)
  • duplicate a windows content to multiple ones
  • create a scrolling terminal inside a window

Limitations

  • no error handling whatsover
  • no real scroll handling for the terminal
  • when calling into a display from an interrupt, yoiu need to set _Semaphore::setAbort(true)_ , otherwise your program can lock up (the ISR waits for the lock to free up, but the other code runs again)

Planned extension / whishes for extension

  • handle proper scrolling
  • add new types of LCD display
  • add other connection modes for existing displays

Source code can be found on github, to allow forking and making contributions.

Example code

#include "mbed.h"

#include "dogm_spi.h"

#include "hd44780_8bit.h"

#include "subwindow.h"

#include "teewindow.h"

#include "terminal.h"

#include "multiwindow.h"

int main( void ) {

    // create an instance for the HD44780 display (2 lines, 16 chars)

    BusOut *data=new BusOut(p21,p22,p23,p24,p25,p26,p27,p28);

    HD44780LCD8bit* lcd1=new HD44780LCD8bit(16,2,data, p20, p19);

    lcd1->init();

    // and write the usual hello world

    lcd1->writeText(0,0,"hello");

    lcd1->writeText(1,4,"world");

    // create a LCD instance for the dogm162 display

    DogmLCDSPI* lcd2=new DogmLCDSPI(

        16, // width

        2,  // height

        new SPI(p5, NC, p7), // dataOut, no dataIn, clock

        p9, // enable

        p8  // RS

    );

    lcd2->init();

    // and write the german hello world

    lcd2->writeText(0,0,"hallo");

    lcd2->writeText(1,4,"welt!");

    // create a sub window on each display, spanning the right half of the
displays

    SubWindow *w1=new SubWindow(lcd1,8,0,8,2);

    SubWindow *w2=new SubWindow(lcd2,8,0,8,2);

    // create avector of all sub windows, for later use

    vector<Window*> lcds;

    lcds.push_back(w1);

    lcds.push_back(w2);


    // the tee window will write to both sub windows at once

    Window* tw=new TeeWindow(lcds);


    // so write to both display at the same time

    tw->writeText(0,0,"00");

    tw->writeText(1,1,"11");

    wait(1);


    // create a terminal which also is dulicated to both displays

    // write some text to it and scroll

    Terminal t(tw);

    t.clear();

    t.writeText(0,0,"1234");

    t.writeText(1,1,"abcd");

    wait(1);

    t.addText("Hello");

    wait(1);

    t.addText("World");

    wait(1);

    t.addText("and");

    wait(1);

    t.addText("even");

    wait(1);

    t.addText("some");

    wait(1);

    t.addText("more");

    // create 2 subwindows for the left half of both displays

    SubWindow *w3=new SubWindow(lcd1,0,0,8,2);

    SubWindow *w4=new SubWindow(lcd2,0,0,8,2);

    vector<Window*> lcds2;

    lcds2.push_back(w3);

    lcds2.push_back(w4);

    // create a window spanning both sub windows (and therefore both display)

    MultiWindow* mw=new MultiWindow(lcds2);

    // and a terminal on it - which means it scrolls across both displays

    Terminal t2(mw);

    t2.clear();

    t2.writeText(0,0,"1234");

    t2.writeText(1,1,"abcd");

    wait(1);

    t2.addText("Hello");

    wait(1);

    t2.addText("World");

    wait(1);

    t2.addText("and");

    wait(1);

    t2.addText("even");

    wait(1);

    t2.addText("some");

    wait(1);

    t2.addText("more");

}


5 comments on LCDWindow:

06 Mar 2011

I get this error: "Cannot open source input file "TextLCD.h": No such file or directory (E5) in file "LcdWindow/textlcdadapter.h"

I try to use a SED1335 display

31 Mar 2012

Joram _ wrote:

TextLCD.h

Hi, I'm new with mbed and would like to get my DOG-M 3x16 with SPI running. But I get the same problem as Joram_ Thanks for any suggestions.

Cheers!

01 Apr 2012

You either need to include the TextLCD library or remove the textlcdadapter.h file from the project. This class is intended as a bridge to support TextLCD too.

03 Jan 2016

Hi! I want to use your library with TextLCD. But I can't figure out how I have to declare the lcd-object. It should be of class TextLCD but also needs to "know" your classes. I've tried with

TextLCDAdapter *lcd2 = new TextLCDAdapter(lcd);

where lcd is of type TextLCD. But I get https://developer.mbed.org/cookbook/Compiler-Error-322

Have you got an example how to use your Library with the TextLCD-Library? I'm not that firm with C++.

Charly

04 Jan 2016

Hi! After doing some reseach in C++-basics and drawing a class diagramm, I've found a solution for my problem.

In TextLCDAdapter the two methods character() and writeText() were missing.

void TextLCDAdapter::writeText(const unsigned int column, const unsigned int row, const char text[]){
    _lcd->locate(column,row);
    int i=0;
    while(text[i]!=0)
    {
        _lcd->putc(text[i]);
        i++;
    }
}

void TextLCDAdapter::character(int column, int row, int c) {
    _lcd->locate(column,row);
    _lcd->putc(c);
}

I also had to remove the code for semaphore, as this doesn't work anymore (at least on LPC1768 - I didn't search for a replacement...) and replace TextLCD by TextLCD_Base.

With this two modifications I am able to use the new Enhanced-Version of TextLCD https://developer.mbed.org/users/wim/notebook/textlcd-enhanced/ and this library with a 40x4LCD (via SPI).

Thanks - Charly

Please log in to post comments.