16x1 panels are actually handled as 8x2 panels. To handle them as named I added a new type LCD16x1

Dependencies:   mbed

Committer:
tlunzer
Date:
Tue May 24 04:46:36 2011 +0000
Revision:
0:7781fb254c42
Added Support for 16x1 LCD panels

Who changed what in which revision?

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