hw

Dependents:   wave_player_mp3

Committer:
zchen311
Date:
Sun Jul 14 20:29:29 2013 +0000
Revision:
0:d45fa961da1b
done

Who changed what in which revision?

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