Dependents:   eParking

Committer:
satriabtp
Date:
Wed Jun 13 08:51:44 2012 +0000
Revision:
0:dabc223d3e03

        

Who changed what in which revision?

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