Alpha numeric LCD Library with support for 40x2 display

Dependencies:   mbed

Committer:
tonydbeck
Date:
Sat Jun 12 01:17:02 2010 +0000
Revision:
0:7e92a1d71370

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tonydbeck 0:7e92a1d71370 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
tonydbeck 0:7e92a1d71370 2 * Copyright (c) 2007-2010, sford
tonydbeck 0:7e92a1d71370 3 *
tonydbeck 0:7e92a1d71370 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
tonydbeck 0:7e92a1d71370 5 * of this software and associated documentation files (the "Software"), to deal
tonydbeck 0:7e92a1d71370 6 * in the Software without restriction, including without limitation the rights
tonydbeck 0:7e92a1d71370 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tonydbeck 0:7e92a1d71370 8 * copies of the Software, and to permit persons to whom the Software is
tonydbeck 0:7e92a1d71370 9 * furnished to do so, subject to the following conditions:
tonydbeck 0:7e92a1d71370 10 *
tonydbeck 0:7e92a1d71370 11 * The above copyright notice and this permission notice shall be included in
tonydbeck 0:7e92a1d71370 12 * all copies or substantial portions of the Software.
tonydbeck 0:7e92a1d71370 13 *
tonydbeck 0:7e92a1d71370 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tonydbeck 0:7e92a1d71370 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tonydbeck 0:7e92a1d71370 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tonydbeck 0:7e92a1d71370 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tonydbeck 0:7e92a1d71370 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tonydbeck 0:7e92a1d71370 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tonydbeck 0:7e92a1d71370 20 * THE SOFTWARE.
tonydbeck 0:7e92a1d71370 21 */
tonydbeck 0:7e92a1d71370 22
tonydbeck 0:7e92a1d71370 23 #ifndef MBED_TEXTLCD_H
tonydbeck 0:7e92a1d71370 24 #define MBED_TEXTLCD_H
tonydbeck 0:7e92a1d71370 25
tonydbeck 0:7e92a1d71370 26 #include "mbed.h"
tonydbeck 0:7e92a1d71370 27
tonydbeck 0:7e92a1d71370 28 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
tonydbeck 0:7e92a1d71370 29 *
tonydbeck 0:7e92a1d71370 30 * Currently supports 16x2, 20x2 and 20x4 panels
tonydbeck 0:7e92a1d71370 31 *
tonydbeck 0:7e92a1d71370 32 * @code
tonydbeck 0:7e92a1d71370 33 * #include "mbed.h"
tonydbeck 0:7e92a1d71370 34 * #include "TextLCD.h"
tonydbeck 0:7e92a1d71370 35 *
tonydbeck 0:7e92a1d71370 36 * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3
tonydbeck 0:7e92a1d71370 37 *
tonydbeck 0:7e92a1d71370 38 * int main() {
tonydbeck 0:7e92a1d71370 39 * lcd.printf("Hello World!\n");
tonydbeck 0:7e92a1d71370 40 * }
tonydbeck 0:7e92a1d71370 41 * @endcode
tonydbeck 0:7e92a1d71370 42 */
tonydbeck 0:7e92a1d71370 43 class TextLCD : public Stream {
tonydbeck 0:7e92a1d71370 44 public:
tonydbeck 0:7e92a1d71370 45
tonydbeck 0:7e92a1d71370 46 /** LCD panel format */
tonydbeck 0:7e92a1d71370 47 enum LCDType {
tonydbeck 0:7e92a1d71370 48 LCD16x2 /**< 16x2 LCD panel (default) */
tonydbeck 0:7e92a1d71370 49 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
tonydbeck 0:7e92a1d71370 50 , LCD20x2 /**< 20x2 LCD panel */
tonydbeck 0:7e92a1d71370 51 , LCD20x4 /**< 20x4 LCD panel */
tonydbeck 0:7e92a1d71370 52 , LCD40x2 /**< 40x2 LCD panel */
tonydbeck 0:7e92a1d71370 53 };
tonydbeck 0:7e92a1d71370 54
tonydbeck 0:7e92a1d71370 55 /** Create a TextLCD interface
tonydbeck 0:7e92a1d71370 56 *
tonydbeck 0:7e92a1d71370 57 * @param rs Instruction/data control line
tonydbeck 0:7e92a1d71370 58 * @param e Enable line (clock)
tonydbeck 0:7e92a1d71370 59 * @param d0-d3 Data lines
tonydbeck 0:7e92a1d71370 60 * @param type Sets the panel size/addressing mode (default = LCD16x2)
tonydbeck 0:7e92a1d71370 61 */
tonydbeck 0:7e92a1d71370 62 TextLCD(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2);
tonydbeck 0:7e92a1d71370 63
tonydbeck 0:7e92a1d71370 64 #if DOXYGEN_ONLY
tonydbeck 0:7e92a1d71370 65 /** Write a character to the LCD
tonydbeck 0:7e92a1d71370 66 *
tonydbeck 0:7e92a1d71370 67 * @param c The character to write to the display
tonydbeck 0:7e92a1d71370 68 */
tonydbeck 0:7e92a1d71370 69 int putc(int c);
tonydbeck 0:7e92a1d71370 70
tonydbeck 0:7e92a1d71370 71 /** Write a formated string to the LCD
tonydbeck 0:7e92a1d71370 72 *
tonydbeck 0:7e92a1d71370 73 * @param format A printf-style format string, followed by the
tonydbeck 0:7e92a1d71370 74 * variables to use in formating the string.
tonydbeck 0:7e92a1d71370 75 */
tonydbeck 0:7e92a1d71370 76 int printf(const char* format, ...);
tonydbeck 0:7e92a1d71370 77 #endif
tonydbeck 0:7e92a1d71370 78
tonydbeck 0:7e92a1d71370 79 /** Locate to a screen column and row
tonydbeck 0:7e92a1d71370 80 *
tonydbeck 0:7e92a1d71370 81 * @param column The horizontal position from the left, indexed from 0
tonydbeck 0:7e92a1d71370 82 * @param row The vertical position from the top, indexed from 0
tonydbeck 0:7e92a1d71370 83 */
tonydbeck 0:7e92a1d71370 84 void locate(int column, int row);
tonydbeck 0:7e92a1d71370 85
tonydbeck 0:7e92a1d71370 86 /** Clear the screen and locate to 0,0 */
tonydbeck 0:7e92a1d71370 87 void cls();
tonydbeck 0:7e92a1d71370 88
tonydbeck 0:7e92a1d71370 89 int rows();
tonydbeck 0:7e92a1d71370 90 int columns();
tonydbeck 0:7e92a1d71370 91
tonydbeck 0:7e92a1d71370 92 protected:
tonydbeck 0:7e92a1d71370 93
tonydbeck 0:7e92a1d71370 94 // Stream implementation functions
tonydbeck 0:7e92a1d71370 95 virtual int _putc(int value);
tonydbeck 0:7e92a1d71370 96 virtual int _getc();
tonydbeck 0:7e92a1d71370 97
tonydbeck 0:7e92a1d71370 98 int address(int column, int row);
tonydbeck 0:7e92a1d71370 99 void character(int column, int row, int c);
tonydbeck 0:7e92a1d71370 100 void writeByte(int value);
tonydbeck 0:7e92a1d71370 101 void writeCommand(int command);
tonydbeck 0:7e92a1d71370 102 void writeData(int data);
tonydbeck 0:7e92a1d71370 103
tonydbeck 0:7e92a1d71370 104 DigitalOut _rs, _e;
tonydbeck 0:7e92a1d71370 105 BusOut _d;
tonydbeck 0:7e92a1d71370 106 LCDType _type;
tonydbeck 0:7e92a1d71370 107
tonydbeck 0:7e92a1d71370 108 int _column;
tonydbeck 0:7e92a1d71370 109 int _row;
tonydbeck 0:7e92a1d71370 110 };
tonydbeck 0:7e92a1d71370 111
tonydbeck 0:7e92a1d71370 112 #endif