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