TextLCD library for controlling various LCD panels based on the HD44780 4-bit interface. Includes support for custom character bitmaps.

Dependents:   HD44780-LCD_with_Bluetooth

Fork of TextLCD by Simon Ford

Examples

Hello world in custom font

#include "mbed.h"
#include "TextLCD.h"

int main() {
    lcd=new TextLCD(D8, D9, D4, D5, D6, D7);


    char c_H[]={0x1b,0x1b,0x1b,0x1f,0x1b,0x1b,0x1b,0x1b};
    char c_e[]={0x0,0x0,0xe,0x1b,0x1f,0x18,0x18,0xf};
    char c_l[]={0x6,0x6,0x6,0x6,0x6,0x6,0x6,0x6};
    char c_o[]={0x0,0x0,0xe,0x1b,0x1b,0x1b,0x1b,0xe};
    char c_W[]={0x1b,0x1b,0x1b,0x1b,0x1f,0x1f,0x1f,0x1b};
    char c_r[]={0x0,0x0,0xe,0x1b,0x18,0x18,0x18,0x18};
    char c_d[]={0x3,0x3,0xf,0x1b,0x1b,0x1b,0x1b,0xf};

    lcd->defineChar(1, c_H);
    lcd->putc(1);
    lcd->defineChar(2, c_e);
    lcd->putc(2);
    lcd->defineChar(3, c_l);
    lcd->putc(3);
    lcd->putc(3);
    lcd->defineChar(4, c_o);
    lcd->putc(4);
    lcd->putc(32);
    lcd->defineChar(5, c_W);
    lcd->putc(5);
    lcd->putc(4);
    lcd->defineChar(6, c_r);
    lcd->putc(6);
    lcd->putc(3);
    lcd->defineChar(7, c_d);
    lcd->putc(7);

    while (1) {
    }
}

Animated busy indicator

This animation only uses 1 of the 8 custom character slots, and can be used like a regular character in the output and will automatically animate in-place. Any number of the animated characters can be displayed on the display at once using this animation technique.

#include "mbed.h"
#include "TextLCD.h"

int main() {
    lcd=new TextLCD(D8, D9, D4, D5, D6, D7);

    //The 7 animation characters
    char spin[]={   0x4,0x4,0x4,0x4,0x4,0x4,0x4,0x0,
                    0x2,0x2,0x2,0x4,0x8,0x8,0x8,0x0,
                    0x1,0x2,0x2,0x4,0x8,0x8,0x10,0x0,
                    0x0,0x0,0x3,0x4,0x18,0x0,0x0,0x0,
                    0x0,0x0,0x0,0x1f,0x0,0x0,0x0,0x0,
                    0x0,0x0,0x18,0x4,0x3,0x0,0x0,0x0,
                    0x10,0x8,0x8,0x4,0x2,0x2,0x01,0x0
                };

    //Output text.
    lcd->printf("\1 Please  wait \1");
    
    //Animation loop
    int frame=0;
    while (1) {
        lcd->defineChar(1, spin+frame*8);
        frame=(frame+1)%(sizeof(spin)/8);
        wait(.14);
    }
Committer:
simon
Date:
Sat May 22 18:18:19 2010 +0000
Revision:
0:edfb85c53631

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:edfb85c53631 1 /* mbed TextDisplay Library Base Class
simon 0:edfb85c53631 2 * Copyright (c) 2007-2010, sford
simon 0:edfb85c53631 3 *
simon 0:edfb85c53631 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:edfb85c53631 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:edfb85c53631 6 * in the Software without restriction, including without limitation the rights
simon 0:edfb85c53631 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:edfb85c53631 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:edfb85c53631 9 * furnished to do so, subject to the following conditions:
simon 0:edfb85c53631 10 *
simon 0:edfb85c53631 11 * The above copyright notice and this permission notice shall be included in
simon 0:edfb85c53631 12 * all copies or substantial portions of the Software.
simon 0:edfb85c53631 13 *
simon 0:edfb85c53631 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:edfb85c53631 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:edfb85c53631 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:edfb85c53631 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:edfb85c53631 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:edfb85c53631 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:edfb85c53631 20 * THE SOFTWARE.
simon 0:edfb85c53631 21 */
simon 0:edfb85c53631 22
simon 0:edfb85c53631 23 #include "TextDisplay.h"
simon 0:edfb85c53631 24
simon 0:edfb85c53631 25 TextDisplay::TextDisplay() {
simon 0:edfb85c53631 26 _row = 0;
simon 0:edfb85c53631 27 _column = 0;
simon 0:edfb85c53631 28 }
simon 0:edfb85c53631 29
simon 0:edfb85c53631 30 int TextDisplay::_putc(int value) {
simon 0:edfb85c53631 31 if(value == '\n') {
simon 0:edfb85c53631 32 _column = 0;
simon 0:edfb85c53631 33 _row++;
simon 0:edfb85c53631 34 if(_row >= rows()) {
simon 0:edfb85c53631 35 _row = 0;
simon 0:edfb85c53631 36 }
simon 0:edfb85c53631 37 } else {
simon 0:edfb85c53631 38 character(_column, _row, value);
simon 0:edfb85c53631 39 _column++;
simon 0:edfb85c53631 40 if(_column >= columns()) {
simon 0:edfb85c53631 41 _column = 0;
simon 0:edfb85c53631 42 _row++;
simon 0:edfb85c53631 43 if(_row >= rows()) {
simon 0:edfb85c53631 44 _row = 0;
simon 0:edfb85c53631 45 }
simon 0:edfb85c53631 46 }
simon 0:edfb85c53631 47 }
simon 0:edfb85c53631 48 return value;
simon 0:edfb85c53631 49 }
simon 0:edfb85c53631 50
simon 0:edfb85c53631 51 // a basic cls implementation, that should generally be overwritten
simon 0:edfb85c53631 52 // with a more efficient implementation
simon 0:edfb85c53631 53 void TextDisplay::cls() {
simon 0:edfb85c53631 54 locate(0, 0);
simon 0:edfb85c53631 55 for(int i=0; i<columns()*rows(); i++) {
simon 0:edfb85c53631 56 putc(' ');
simon 0:edfb85c53631 57 }
simon 0:edfb85c53631 58 }
simon 0:edfb85c53631 59
simon 0:edfb85c53631 60 void TextDisplay::locate(int column, int row) {
simon 0:edfb85c53631 61 _column = column;
simon 0:edfb85c53631 62 _row = row;
simon 0:edfb85c53631 63 }
simon 0:edfb85c53631 64
simon 0:edfb85c53631 65 int TextDisplay::_getc() {
simon 0:edfb85c53631 66 return -1;
simon 0:edfb85c53631 67 }
simon 0:edfb85c53631 68
simon 0:edfb85c53631 69 void TextDisplay::foreground(int colour) {
simon 0:edfb85c53631 70 _foreground = colour;
simon 0:edfb85c53631 71 }
simon 0:edfb85c53631 72
simon 0:edfb85c53631 73 void TextDisplay::background(int colour) {
simon 0:edfb85c53631 74 _background = colour;
simon 0:edfb85c53631 75 }