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