This is a modified version of TextLCD on the Cookbook for 20X4 LCD specific. This does not control RW line, so we can reduce the number of pin usage on the mbed.

Dependencies:   mbed

Committer:
ym1784
Date:
Fri May 14 21:19:39 2010 +0000
Revision:
0:f84245f91a5a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ym1784 0:f84245f91a5a 1 /* mbed TextLCD Library
ym1784 0:f84245f91a5a 2 * Copyright (c) 2007-2009 sford
ym1784 0:f84245f91a5a 3 * Released under the MIT License: http://mbed.org/license/mit
ym1784 0:f84245f91a5a 4 *
ym1784 0:f84245f91a5a 5 * TODO: Needs serious rework/neatening up!
ym1784 0:f84245f91a5a 6 */
ym1784 0:f84245f91a5a 7
ym1784 0:f84245f91a5a 8 /*
ym1784 0:f84245f91a5a 9 * 2010/05/14 modified for 20X4 LCD by ym1784
ym1784 0:f84245f91a5a 10 */
ym1784 0:f84245f91a5a 11
ym1784 0:f84245f91a5a 12 #ifndef MBED_TEXTLCD_20X4_H
ym1784 0:f84245f91a5a 13 #define MBED_TEXTLCD_20X4_H
ym1784 0:f84245f91a5a 14
ym1784 0:f84245f91a5a 15 #include "Stream.h"
ym1784 0:f84245f91a5a 16 #include "DigitalOut.h"
ym1784 0:f84245f91a5a 17 #include "BusOut.h"
ym1784 0:f84245f91a5a 18
ym1784 0:f84245f91a5a 19 namespace mbed {
ym1784 0:f84245f91a5a 20
ym1784 0:f84245f91a5a 21 /* Class: TextLCD_20X4
ym1784 0:f84245f91a5a 22 * A 20x4 Text LCD controller ... ym1784
ym1784 0:f84245f91a5a 23 *
ym1784 0:f84245f91a5a 24 * Allows you to print to a Text LCD screen, and locate/cls. Could be
ym1784 0:f84245f91a5a 25 * turned in to a more generic libray.
ym1784 0:f84245f91a5a 26 *
ym1784 0:f84245f91a5a 27 * If you are connecting multiple displays, you can connect them all in
ym1784 0:f84245f91a5a 28 * parallel except for the enable (e) pin, which must be unique for each
ym1784 0:f84245f91a5a 29 * display.
ym1784 0:f84245f91a5a 30 *
ym1784 0:f84245f91a5a 31 * Example:
ym1784 0:f84245f91a5a 32 * > #include "mbed.h"
ym1784 0:f84245f91a5a 33 * > #include "TextLCD_20X4.h"
ym1784 0:f84245f91a5a 34 * >
ym1784 0:f84245f91a5a 35 * > TextLCD_20X4 lcd(p21, p22, p23, p24, p25, p26); // rs, e, d0, d1, d2, d3
ym1784 0:f84245f91a5a 36 * >
ym1784 0:f84245f91a5a 37 * > int main() {
ym1784 0:f84245f91a5a 38 * > lcd.printf("Hello World!");
ym1784 0:f84245f91a5a 39 * > }
ym1784 0:f84245f91a5a 40 */
ym1784 0:f84245f91a5a 41 class TextLCD_20X4 : public Stream {
ym1784 0:f84245f91a5a 42
ym1784 0:f84245f91a5a 43 public:
ym1784 0:f84245f91a5a 44 /* Constructor: TextLCD_20X4
ym1784 0:f84245f91a5a 45 * Create a TextLCD_20X4 object, connected to the specified pins
ym1784 0:f84245f91a5a 46 *
ym1784 0:f84245f91a5a 47 * All signals must be connected to DigitalIn compatible pins.
ym1784 0:f84245f91a5a 48 *
ym1784 0:f84245f91a5a 49 * Variables:
ym1784 0:f84245f91a5a 50 * rs - Used to specify data or command
ym1784 0:f84245f91a5a 51 * e - enable
ym1784 0:f84245f91a5a 52 * d0..d3 - The data lines
ym1784 0:f84245f91a5a 53 */
ym1784 0:f84245f91a5a 54 TextLCD_20X4(PinName rs, PinName e, PinName d0, PinName d1,
ym1784 0:f84245f91a5a 55 PinName d2, PinName d3, int columns = 20, int rows = 4);
ym1784 0:f84245f91a5a 56
ym1784 0:f84245f91a5a 57 #if 0 // Inhereted from Stream, for documentation only
ym1784 0:f84245f91a5a 58 /* Function: putc
ym1784 0:f84245f91a5a 59 * Write a character
ym1784 0:f84245f91a5a 60 *
ym1784 0:f84245f91a5a 61 * Variables:
ym1784 0:f84245f91a5a 62 * c - The character to write to the serial port
ym1784 0:f84245f91a5a 63 */
ym1784 0:f84245f91a5a 64 int putc(int c);
ym1784 0:f84245f91a5a 65
ym1784 0:f84245f91a5a 66 /* Function: printf
ym1784 0:f84245f91a5a 67 * Write a formated string
ym1784 0:f84245f91a5a 68 *
ym1784 0:f84245f91a5a 69 * Variables:
ym1784 0:f84245f91a5a 70 * format - A printf-style format string, followed by the
ym1784 0:f84245f91a5a 71 * variables to use in formating the string.
ym1784 0:f84245f91a5a 72 */
ym1784 0:f84245f91a5a 73 int printf(const char* format, ...);
ym1784 0:f84245f91a5a 74 #endif
ym1784 0:f84245f91a5a 75
ym1784 0:f84245f91a5a 76 /* Function: locate
ym1784 0:f84245f91a5a 77 * Locate to a certian position
ym1784 0:f84245f91a5a 78 *
ym1784 0:f84245f91a5a 79 * Variables:
ym1784 0:f84245f91a5a 80 * column - the column to locate to, from 0..19
ym1784 0:f84245f91a5a 81 * row - the row to locate to, from 0..3
ym1784 0:f84245f91a5a 82 */
ym1784 0:f84245f91a5a 83 virtual void locate(int column, int row);
ym1784 0:f84245f91a5a 84
ym1784 0:f84245f91a5a 85 /* Function: cls
ym1784 0:f84245f91a5a 86 * Clear the screen
ym1784 0:f84245f91a5a 87 */
ym1784 0:f84245f91a5a 88 virtual void cls();
ym1784 0:f84245f91a5a 89
ym1784 0:f84245f91a5a 90 virtual void reset();
ym1784 0:f84245f91a5a 91
ym1784 0:f84245f91a5a 92 //protected:
ym1784 0:f84245f91a5a 93
ym1784 0:f84245f91a5a 94 void clock();
ym1784 0:f84245f91a5a 95 void writeData(int data);
ym1784 0:f84245f91a5a 96 void writeCommand(int command);
ym1784 0:f84245f91a5a 97 void writeByte(int value);
ym1784 0:f84245f91a5a 98 void writeNibble(int value);
ym1784 0:f84245f91a5a 99 virtual int _putc(int c);
ym1784 0:f84245f91a5a 100 virtual int _getc();
ym1784 0:f84245f91a5a 101 virtual void newline();
ym1784 0:f84245f91a5a 102
ym1784 0:f84245f91a5a 103 int _row;
ym1784 0:f84245f91a5a 104 int _column;
ym1784 0:f84245f91a5a 105 DigitalOut _rs, _e;
ym1784 0:f84245f91a5a 106 BusOut _d;
ym1784 0:f84245f91a5a 107 int _columns;
ym1784 0:f84245f91a5a 108 int _rows;
ym1784 0:f84245f91a5a 109 int address;
ym1784 0:f84245f91a5a 110 };
ym1784 0:f84245f91a5a 111
ym1784 0:f84245f91a5a 112 }
ym1784 0:f84245f91a5a 113
ym1784 0:f84245f91a5a 114 #endif