Dependents:   revcounter SDFileSystem_Load TMP102HelloWorld KnightRiderOptimized ... more

Committer:
tlunzer
Date:
Tue May 24 05:13:04 2011 +0000
Revision:
0:a7c08c5305b3
added support for 16x1 panels

Who changed what in which revision?

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