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