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