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