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