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