Based on the NewTextLib, I made a modification for using this lib on the Elmicro Testbed with display GDM2004D

Dependencies:   mbed

Committer:
TP
Date:
Sat Jun 11 20:34:14 2011 +0000
Revision:
0:9c69fa6c1120

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TP 0:9c69fa6c1120 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
TP 0:9c69fa6c1120 2 * Copyright (c) 2007-2010, sford, http://mbed.org
TP 0:9c69fa6c1120 3 * 2011-06-11 TP modified for Elmicro Testbed with display GDM4000D
TP 0:9c69fa6c1120 4 *
TP 0:9c69fa6c1120 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
TP 0:9c69fa6c1120 6 * of this software and associated documentation files (the "Software"), to deal
TP 0:9c69fa6c1120 7 * in the Software without restriction, including without limitation the rights
TP 0:9c69fa6c1120 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
TP 0:9c69fa6c1120 9 * copies of the Software, and to permit persons to whom the Software is
TP 0:9c69fa6c1120 10 * furnished to do so, subject to the following conditions:
TP 0:9c69fa6c1120 11 *
TP 0:9c69fa6c1120 12 * The above copyright notice and this permission notice shall be included in
TP 0:9c69fa6c1120 13 * all copies or substantial portions of the Software.
TP 0:9c69fa6c1120 14 *
TP 0:9c69fa6c1120 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
TP 0:9c69fa6c1120 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
TP 0:9c69fa6c1120 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
TP 0:9c69fa6c1120 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
TP 0:9c69fa6c1120 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
TP 0:9c69fa6c1120 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
TP 0:9c69fa6c1120 21 * THE SOFTWARE.
TP 0:9c69fa6c1120 22 */
TP 0:9c69fa6c1120 23
TP 0:9c69fa6c1120 24 #ifndef MBED_TEXTLCD_H
TP 0:9c69fa6c1120 25 #define MBED_TEXTLCD_H
TP 0:9c69fa6c1120 26
TP 0:9c69fa6c1120 27 #include "mbed.h"
TP 0:9c69fa6c1120 28
TP 0:9c69fa6c1120 29 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
TP 0:9c69fa6c1120 30 *
TP 0:9c69fa6c1120 31 * Currently supports 16x2, 20x2 and 20x4 panels
TP 0:9c69fa6c1120 32 *
TP 0:9c69fa6c1120 33 * @code
TP 0:9c69fa6c1120 34 * #include "mbed.h"
TP 0:9c69fa6c1120 35 * #include "NewTextLCD.h"
TP 0:9c69fa6c1120 36 *
TP 0:9c69fa6c1120 37 * TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4); // rs, rw, e, d4-d7
TP 0:9c69fa6c1120 38 *
TP 0:9c69fa6c1120 39 * int main() {
TP 0:9c69fa6c1120 40 * lcd.printf("Hello mbed\n");
TP 0:9c69fa6c1120 41 *
TP 0:9c69fa6c1120 42 * //define user chars
TP 0:9c69fa6c1120 43 * int pattern[8];
TP 0:9c69fa6c1120 44 * int pattern1[8];
TP 0:9c69fa6c1120 45 * pattern[0] = 1; // *
TP 0:9c69fa6c1120 46 * pattern[1] = 3; // **
TP 0:9c69fa6c1120 47 * pattern[2] = 5; // * *
TP 0:9c69fa6c1120 48 * pattern[3] = 9; // * *
TP 0:9c69fa6c1120 49 * pattern[4] = 0x11; // * *
TP 0:9c69fa6c1120 50 * pattern[5] = 0x19; // ** *
TP 0:9c69fa6c1120 51 * pattern[6] = 0x1d; // *** *
TP 0:9c69fa6c1120 52 * pattern[7] = 0x1f; // *****
TP 0:9c69fa6c1120 53 *
TP 0:9c69fa6c1120 54 * pattern1[0] = 0x10; // *
TP 0:9c69fa6c1120 55 * pattern1[1] = 0x18; // **
TP 0:9c69fa6c1120 56 * pattern1[2] = 0x14; // * *
TP 0:9c69fa6c1120 57 * pattern1[3] = 0x12; // * *
TP 0:9c69fa6c1120 58 * pattern1[4] = 0x11; // * *
TP 0:9c69fa6c1120 59 * pattern1[5] = 0x13; // * **
TP 0:9c69fa6c1120 60 * pattern1[6] = 0x17; // * ***
TP 0:9c69fa6c1120 61 * pattern1[7] = 0x1f; // *****
TP 0:9c69fa6c1120 62 *
TP 0:9c69fa6c1120 63 * lcd.writeCGRAM(0, pattern);
TP 0:9c69fa6c1120 64 * lcd.writeCGRAM(1, pattern1);
TP 0:9c69fa6c1120 65 *
TP 0:9c69fa6c1120 66 * lcd.locate(15,0);
TP 0:9c69fa6c1120 67 * lcd.putc(0); // user pattern 0
TP 0:9c69fa6c1120 68 * lcd.putc(1); // user pattern 1
TP 0:9c69fa6c1120 69 * }
TP 0:9c69fa6c1120 70 * @endcode
TP 0:9c69fa6c1120 71 */
TP 0:9c69fa6c1120 72 class TextLCD : public Stream {
TP 0:9c69fa6c1120 73 public:
TP 0:9c69fa6c1120 74
TP 0:9c69fa6c1120 75 /** LCD panel format */
TP 0:9c69fa6c1120 76 enum LCDType {
TP 0:9c69fa6c1120 77 LCD16x2 /**< 16x2 LCD panel (default) */
TP 0:9c69fa6c1120 78 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
TP 0:9c69fa6c1120 79 , LCD20x2 /**< 20x2 LCD panel */
TP 0:9c69fa6c1120 80 , LCD20x4 /**< 20x4 LCD panel */
TP 0:9c69fa6c1120 81 , LCD24x2 /**< 24x2 LCD panel */
TP 0:9c69fa6c1120 82 , LCDuser /** User defined LCD, rows/columns must be set */
TP 0:9c69fa6c1120 83 };
TP 0:9c69fa6c1120 84
TP 0:9c69fa6c1120 85 /** Create a TextLCD interface
TP 0:9c69fa6c1120 86 *
TP 0:9c69fa6c1120 87 * @param rs Instruction/data control line
TP 0:9c69fa6c1120 88 * @param rw R/W line
TP 0:9c69fa6c1120 89 * @param e Enable line (clock)
TP 0:9c69fa6c1120 90 * @param d4-d7 Data lines
TP 0:9c69fa6c1120 91 * @param type Sets the panel size/addressing mode (default = LCD16x2)
TP 0:9c69fa6c1120 92 */
TP 0:9c69fa6c1120 93 TextLCD(PinName rs, PinName rw, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
TP 0:9c69fa6c1120 94
TP 0:9c69fa6c1120 95 #if DOXYGEN_ONLY
TP 0:9c69fa6c1120 96 /** Write a character to the LCD
TP 0:9c69fa6c1120 97 *
TP 0:9c69fa6c1120 98 * @param c The character to write to the display
TP 0:9c69fa6c1120 99 */
TP 0:9c69fa6c1120 100 int putc(int c);
TP 0:9c69fa6c1120 101
TP 0:9c69fa6c1120 102 /** Write a formated string to the LCD
TP 0:9c69fa6c1120 103 *
TP 0:9c69fa6c1120 104 * @param format A printf-style format string, followed by the
TP 0:9c69fa6c1120 105 * variables to use in formating the string.
TP 0:9c69fa6c1120 106 */
TP 0:9c69fa6c1120 107 int printf(const char* format, ...);
TP 0:9c69fa6c1120 108 #endif
TP 0:9c69fa6c1120 109
TP 0:9c69fa6c1120 110 /** Locate to a screen column and row
TP 0:9c69fa6c1120 111 *
TP 0:9c69fa6c1120 112 * @param column The horizontal position from the left, indexed from 0
TP 0:9c69fa6c1120 113 * @param row The vertical position from the top, indexed from 0
TP 0:9c69fa6c1120 114 */
TP 0:9c69fa6c1120 115 void locate(int column, int row);
TP 0:9c69fa6c1120 116
TP 0:9c69fa6c1120 117 /** Clear the screen and locate to 0,0 */
TP 0:9c69fa6c1120 118 void cls();
TP 0:9c69fa6c1120 119
TP 0:9c69fa6c1120 120 struct LCDparam {
TP 0:9c69fa6c1120 121 int rows; // number of lines //
TP 0:9c69fa6c1120 122 int columns; // number of columns //
TP 0:9c69fa6c1120 123 int delay; // delay for commands microseconds //
TP 0:9c69fa6c1120 124 int adresses[4]; // start adresses for 4 lines //
TP 0:9c69fa6c1120 125 } LCDparam;
TP 0:9c69fa6c1120 126
TP 0:9c69fa6c1120 127 /** write a user defined char
TP 0:9c69fa6c1120 128 *
TP 0:9c69fa6c1120 129 * @param address The user defined char (0-7)
TP 0:9c69fa6c1120 130 * @param pattern[8] bit pattern 5*8 of char
TP 0:9c69fa6c1120 131 */
TP 0:9c69fa6c1120 132 void writeCGRAM(int address, int pattern[8]);
TP 0:9c69fa6c1120 133
TP 0:9c69fa6c1120 134 /** Get the char at the current position
TP 0:9c69fa6c1120 135 *
TP 0:9c69fa6c1120 136 * int getc()
TP 0:9c69fa6c1120 137 */
TP 0:9c69fa6c1120 138 void writeCommand(int command);
TP 0:9c69fa6c1120 139
TP 0:9c69fa6c1120 140 protected:
TP 0:9c69fa6c1120 141
TP 0:9c69fa6c1120 142 // Stream implementation functions
TP 0:9c69fa6c1120 143 virtual int _putc(int value);
TP 0:9c69fa6c1120 144 virtual int _getc();
TP 0:9c69fa6c1120 145
TP 0:9c69fa6c1120 146 int address(int column, int row);
TP 0:9c69fa6c1120 147 void character(int column, int row, int c);
TP 0:9c69fa6c1120 148 void writeByte(int value);
TP 0:9c69fa6c1120 149 void writeData(int data);
TP 0:9c69fa6c1120 150 void setLCDparam(LCDType _type);
TP 0:9c69fa6c1120 151 DigitalOut _rs, _rw, _e;
TP 0:9c69fa6c1120 152 BusOut _d;
TP 0:9c69fa6c1120 153 LCDType _type;
TP 0:9c69fa6c1120 154
TP 0:9c69fa6c1120 155 int _column;
TP 0:9c69fa6c1120 156 int _row;
TP 0:9c69fa6c1120 157 };
TP 0:9c69fa6c1120 158
TP 0:9c69fa6c1120 159 #endif