private Library copy of TextLCD

Dependents:   eBible ej_RSSfeeder erg y_HM55B ... more

Committer:
davervw
Date:
Sun Feb 27 18:50:36 2011 +0000
Revision:
0:c5318c74f1a9
Revised to support 40x2 and 8x2 screens

Who changed what in which revision?

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