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