Dependents:   Project_Stepper MP3_Player_Touch_Panel_Input_LCD_Display WeatherStation HTTPClientTest ... more

Committer:
benyun
Date:
Wed Aug 03 00:44:54 2011 +0000
Revision:
0:7dd9751172e1

        

Who changed what in which revision?

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