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