Dependents:   geigercounter01 geigercounter04 4_LCD_With_Lib PROJECTFILE ... more

Committer:
mamezu
Date:
Tue Dec 21 07:20:38 2010 +0000
Revision:
0:ffeb3e6c1367

        

Who changed what in which revision?

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