TextLCD_piano adapted to LCD screen with R/W
Fork of TextLCD by
TextLCD.h@9:05c9b97e4a91, 2018-07-02 (annotated)
- Committer:
- Aliened
- Date:
- Mon Jul 02 17:58:56 2018 +0000
- Revision:
- 9:05c9b97e4a91
- Parent:
- 8:308d188a2d3a
Compatibility with R/W pin of Character LCD 16 x 2 character LCD display module:; Manufacturer: Newhaven Display Intl ; Manufacturer part number: NHD-0216HZ-FSW-FBW-33V3C-ND ; Part number: NHD-0216HZ-FSW-FBW-33V3C
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:ac48b187213c | 1 | /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 |
simon | 6:e4cb7ddee0d3 | 2 | * Copyright (c) 2007-2010, sford, http://mbed.org |
simon | 1:ac48b187213c | 3 | * |
simon | 1:ac48b187213c | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 1:ac48b187213c | 5 | * of this software and associated documentation files (the "Software"), to deal |
simon | 1:ac48b187213c | 6 | * in the Software without restriction, including without limitation the rights |
simon | 1:ac48b187213c | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 1:ac48b187213c | 8 | * copies of the Software, and to permit persons to whom the Software is |
simon | 1:ac48b187213c | 9 | * furnished to do so, subject to the following conditions: |
simon | 2:227356c7d12c | 10 | * |
simon | 1:ac48b187213c | 11 | * The above copyright notice and this permission notice shall be included in |
simon | 1:ac48b187213c | 12 | * all copies or substantial portions of the Software. |
simon | 2:227356c7d12c | 13 | * |
simon | 1:ac48b187213c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 1:ac48b187213c | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 1:ac48b187213c | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 1:ac48b187213c | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 1:ac48b187213c | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 1:ac48b187213c | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 1:ac48b187213c | 20 | * THE SOFTWARE. |
simon | 1:ac48b187213c | 21 | */ |
Aliened | 9:05c9b97e4a91 | 22 | |
simon | 1:ac48b187213c | 23 | #ifndef MBED_TEXTLCD_H |
simon | 1:ac48b187213c | 24 | #define MBED_TEXTLCD_H |
Aliened | 9:05c9b97e4a91 | 25 | |
simon | 1:ac48b187213c | 26 | #include "mbed.h" |
Aliened | 9:05c9b97e4a91 | 27 | |
Aliened | 9:05c9b97e4a91 | 28 | /** A TextLCD interface for driving 4-bit HD44780-based LCDs |
simon | 2:227356c7d12c | 29 | * |
simon | 5:a53b3e2d6f1e | 30 | * Currently supports 16x2, 20x2 and 20x4 panels |
simon | 2:227356c7d12c | 31 | * |
simon | 2:227356c7d12c | 32 | * @code |
simon | 2:227356c7d12c | 33 | * #include "mbed.h" |
simon | 2:227356c7d12c | 34 | * #include "TextLCD.h" |
simon | 5:a53b3e2d6f1e | 35 | * |
Aliened | 9:05c9b97e4a91 | 36 | * TextLCD lcd(p10, p12, ,p13, p15, p16, p29, p30); // rs, rw, e, d0-d3 |
simon | 5:a53b3e2d6f1e | 37 | * |
simon | 2:227356c7d12c | 38 | * int main() { |
Aliened | 9:05c9b97e4a91 | 39 | * lcd.printf("Hello mbed\n"); |
Aliened | 9:05c9b97e4a91 | 40 | * |
Aliened | 9:05c9b97e4a91 | 41 | * //define user chars |
Aliened | 9:05c9b97e4a91 | 42 | * int pattern[8]; |
Aliened | 9:05c9b97e4a91 | 43 | * int pattern1[8]; |
Aliened | 9:05c9b97e4a91 | 44 | * pattern[0] = 1; // * |
Aliened | 9:05c9b97e4a91 | 45 | * pattern[1] = 3; // ** |
Aliened | 9:05c9b97e4a91 | 46 | * pattern[2] = 5; // * * |
Aliened | 9:05c9b97e4a91 | 47 | * pattern[3] = 9; // * * |
Aliened | 9:05c9b97e4a91 | 48 | * pattern[4] = 0x11; // * * |
Aliened | 9:05c9b97e4a91 | 49 | * pattern[5] = 0x19; // ** * |
Aliened | 9:05c9b97e4a91 | 50 | * pattern[6] = 0x1d; // *** * |
Aliened | 9:05c9b97e4a91 | 51 | * pattern[7] = 0x1f; // ***** |
Aliened | 9:05c9b97e4a91 | 52 | * |
Aliened | 9:05c9b97e4a91 | 53 | * pattern1[0] = 0x10; // * |
Aliened | 9:05c9b97e4a91 | 54 | * pattern1[1] = 0x18; // ** |
Aliened | 9:05c9b97e4a91 | 55 | * pattern1[2] = 0x14; // * * |
Aliened | 9:05c9b97e4a91 | 56 | * pattern1[3] = 0x12; // * * |
Aliened | 9:05c9b97e4a91 | 57 | * pattern1[4] = 0x11; // * * |
Aliened | 9:05c9b97e4a91 | 58 | * pattern1[5] = 0x13; // * ** |
Aliened | 9:05c9b97e4a91 | 59 | * pattern1[6] = 0x17; // * *** |
Aliened | 9:05c9b97e4a91 | 60 | * pattern1[7] = 0x1f; // ***** |
Aliened | 9:05c9b97e4a91 | 61 | * |
Aliened | 9:05c9b97e4a91 | 62 | * lcd.writeCGRAM(0, pattern); |
Aliened | 9:05c9b97e4a91 | 63 | * lcd.writeCGRAM(1, pattern1); |
Aliened | 9:05c9b97e4a91 | 64 | * |
Aliened | 9:05c9b97e4a91 | 65 | * lcd.locate(15,0); |
Aliened | 9:05c9b97e4a91 | 66 | * lcd.putc(0); // user pattern 0 |
Aliened | 9:05c9b97e4a91 | 67 | * lcd.putc(1); // user pattern 1 |
simon | 2:227356c7d12c | 68 | * } |
simon | 2:227356c7d12c | 69 | * @endcode |
simon | 2:227356c7d12c | 70 | */ |
simon | 1:ac48b187213c | 71 | class TextLCD : public Stream { |
simon | 1:ac48b187213c | 72 | public: |
Aliened | 9:05c9b97e4a91 | 73 | |
simon | 2:227356c7d12c | 74 | /** LCD panel format */ |
simon | 1:ac48b187213c | 75 | enum LCDType { |
simon | 2:227356c7d12c | 76 | LCD16x2 /**< 16x2 LCD panel (default) */ |
simon | 2:227356c7d12c | 77 | , LCD16x2B /**< 16x2 LCD panel alternate addressing */ |
simon | 2:227356c7d12c | 78 | , LCD20x2 /**< 20x2 LCD panel */ |
simon | 2:227356c7d12c | 79 | , LCD20x4 /**< 20x4 LCD panel */ |
simon | 1:ac48b187213c | 80 | }; |
Aliened | 9:05c9b97e4a91 | 81 | |
simon | 2:227356c7d12c | 82 | /** Create a TextLCD interface |
simon | 2:227356c7d12c | 83 | * |
simon | 2:227356c7d12c | 84 | * @param rs Instruction/data control line |
simon | 2:227356c7d12c | 85 | * @param e Enable line (clock) |
Aliened | 9:05c9b97e4a91 | 86 | * @param rw read / write |
Aliened | 9:05c9b97e4a91 | 87 | * @param d0-d3 Data lines |
simon | 2:227356c7d12c | 88 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
simon | 2:227356c7d12c | 89 | */ |
Aliened | 9:05c9b97e4a91 | 90 | TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2); |
Aliened | 9:05c9b97e4a91 | 91 | |
simon | 2:227356c7d12c | 92 | #if DOXYGEN_ONLY |
simon | 2:227356c7d12c | 93 | /** Write a character to the LCD |
simon | 2:227356c7d12c | 94 | * |
simon | 2:227356c7d12c | 95 | * @param c The character to write to the display |
simon | 2:227356c7d12c | 96 | */ |
simon | 2:227356c7d12c | 97 | int putc(int c); |
Aliened | 9:05c9b97e4a91 | 98 | |
simon | 2:227356c7d12c | 99 | /** Write a formated string to the LCD |
simon | 2:227356c7d12c | 100 | * |
simon | 2:227356c7d12c | 101 | * @param format A printf-style format string, followed by the |
simon | 2:227356c7d12c | 102 | * variables to use in formating the string. |
simon | 2:227356c7d12c | 103 | */ |
simon | 2:227356c7d12c | 104 | int printf(const char* format, ...); |
simon | 2:227356c7d12c | 105 | #endif |
Aliened | 9:05c9b97e4a91 | 106 | |
simon | 2:227356c7d12c | 107 | /** Locate to a screen column and row |
simon | 2:227356c7d12c | 108 | * |
simon | 2:227356c7d12c | 109 | * @param column The horizontal position from the left, indexed from 0 |
simon | 2:227356c7d12c | 110 | * @param row The vertical position from the top, indexed from 0 |
simon | 2:227356c7d12c | 111 | */ |
simon | 1:ac48b187213c | 112 | void locate(int column, int row); |
Aliened | 9:05c9b97e4a91 | 113 | |
simon | 2:227356c7d12c | 114 | /** Clear the screen and locate to 0,0 */ |
simon | 1:ac48b187213c | 115 | void cls(); |
Aliened | 9:05c9b97e4a91 | 116 | |
simon | 1:ac48b187213c | 117 | int rows(); |
simon | 2:227356c7d12c | 118 | int columns(); |
Aliened | 9:05c9b97e4a91 | 119 | |
Aliened | 9:05c9b97e4a91 | 120 | /** write a user defined char |
Aliened | 9:05c9b97e4a91 | 121 | * |
Aliened | 9:05c9b97e4a91 | 122 | * @param address The user defined char (0-7) |
Aliened | 9:05c9b97e4a91 | 123 | * @param pattern[8] bit pattern 5*8 of char |
Aliened | 9:05c9b97e4a91 | 124 | */ |
Aliened | 9:05c9b97e4a91 | 125 | void writeCGRAM(int address, int pattern[8]); |
Aliened | 9:05c9b97e4a91 | 126 | |
Aliened | 9:05c9b97e4a91 | 127 | /** Get the char at the current position |
Aliened | 9:05c9b97e4a91 | 128 | * |
Aliened | 9:05c9b97e4a91 | 129 | * int getc() |
Aliened | 9:05c9b97e4a91 | 130 | */ |
Aliened | 9:05c9b97e4a91 | 131 | |
simon | 1:ac48b187213c | 132 | protected: |
Aliened | 9:05c9b97e4a91 | 133 | |
simon | 1:ac48b187213c | 134 | // Stream implementation functions |
simon | 1:ac48b187213c | 135 | virtual int _putc(int value); |
simon | 1:ac48b187213c | 136 | virtual int _getc(); |
Aliened | 9:05c9b97e4a91 | 137 | |
simon | 2:227356c7d12c | 138 | int address(int column, int row); |
simon | 2:227356c7d12c | 139 | void character(int column, int row, int c); |
simon | 1:ac48b187213c | 140 | void writeByte(int value); |
simon | 1:ac48b187213c | 141 | void writeCommand(int command); |
simon | 1:ac48b187213c | 142 | void writeData(int data); |
Aliened | 9:05c9b97e4a91 | 143 | int readData(); |
Aliened | 9:05c9b97e4a91 | 144 | void waitBusy(); |
Aliened | 9:05c9b97e4a91 | 145 | DigitalOut _rs, _e, _rw; |
Aliened | 9:05c9b97e4a91 | 146 | BusInOut _d; |
simon | 1:ac48b187213c | 147 | LCDType _type; |
Aliened | 9:05c9b97e4a91 | 148 | |
simon | 1:ac48b187213c | 149 | int _column; |
simon | 1:ac48b187213c | 150 | int _row; |
simon | 1:ac48b187213c | 151 | }; |
Aliened | 9:05c9b97e4a91 | 152 | |
simon | 1:ac48b187213c | 153 | #endif |
Aliened | 9:05c9b97e4a91 | 154 |