PCF2119 library for I/O board
Fork of PCF2119 by
PCF2119.h@9:27f430d086f3, 2014-07-09 (annotated)
- Committer:
- okini3939
- Date:
- Wed Jul 09 03:54:42 2014 +0000
- Revision:
- 9:27f430d086f3
- Parent:
- TextLCD.h@8:308d188a2d3a
- Child:
- 10:d13717a53fe0
1st build;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 9:27f430d086f3 | 1 | /* PCF2119x based I2C LCD Library |
okini3939 | 9:27f430d086f3 | 2 | * Copyright (c) 2014, Hiroshi Suga |
okini3939 | 9:27f430d086f3 | 3 | */ |
simon | 1:ac48b187213c | 4 | /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 |
simon | 6:e4cb7ddee0d3 | 5 | * Copyright (c) 2007-2010, sford, http://mbed.org |
simon | 1:ac48b187213c | 6 | * |
simon | 1:ac48b187213c | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 1:ac48b187213c | 8 | * of this software and associated documentation files (the "Software"), to deal |
simon | 1:ac48b187213c | 9 | * in the Software without restriction, including without limitation the rights |
simon | 1:ac48b187213c | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 1:ac48b187213c | 11 | * copies of the Software, and to permit persons to whom the Software is |
simon | 1:ac48b187213c | 12 | * furnished to do so, subject to the following conditions: |
simon | 2:227356c7d12c | 13 | * |
simon | 1:ac48b187213c | 14 | * The above copyright notice and this permission notice shall be included in |
simon | 1:ac48b187213c | 15 | * all copies or substantial portions of the Software. |
simon | 2:227356c7d12c | 16 | * |
simon | 1:ac48b187213c | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 1:ac48b187213c | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 1:ac48b187213c | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 1:ac48b187213c | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 1:ac48b187213c | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 1:ac48b187213c | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 1:ac48b187213c | 23 | * THE SOFTWARE. |
simon | 1:ac48b187213c | 24 | */ |
simon | 1:ac48b187213c | 25 | |
okini3939 | 9:27f430d086f3 | 26 | #ifndef __PCF2119_H__ |
okini3939 | 9:27f430d086f3 | 27 | #define __PCF2119_H__ |
simon | 1:ac48b187213c | 28 | |
simon | 1:ac48b187213c | 29 | #include "mbed.h" |
simon | 2:227356c7d12c | 30 | |
okini3939 | 9:27f430d086f3 | 31 | /** A PCF2119 interface for driving I2C PCF2119x-based LCDs |
simon | 2:227356c7d12c | 32 | * |
simon | 5:a53b3e2d6f1e | 33 | * Currently supports 16x2, 20x2 and 20x4 panels |
simon | 2:227356c7d12c | 34 | * |
simon | 2:227356c7d12c | 35 | * @code |
simon | 2:227356c7d12c | 36 | * #include "mbed.h" |
okini3939 | 9:27f430d086f3 | 37 | * #include "PCF2119.h" |
simon | 5:a53b3e2d6f1e | 38 | * |
okini3939 | 9:27f430d086f3 | 39 | * TextLCD lcd(p10, p12, p15, p30); // sda, sck, reset |
simon | 5:a53b3e2d6f1e | 40 | * |
simon | 2:227356c7d12c | 41 | * int main() { |
simon | 2:227356c7d12c | 42 | * lcd.printf("Hello World!\n"); |
simon | 2:227356c7d12c | 43 | * } |
simon | 2:227356c7d12c | 44 | * @endcode |
simon | 2:227356c7d12c | 45 | */ |
okini3939 | 9:27f430d086f3 | 46 | class PCF2119 : public Stream { |
simon | 1:ac48b187213c | 47 | public: |
simon | 1:ac48b187213c | 48 | |
simon | 2:227356c7d12c | 49 | /** LCD panel format */ |
simon | 1:ac48b187213c | 50 | enum LCDType { |
simon | 2:227356c7d12c | 51 | LCD16x2 /**< 16x2 LCD panel (default) */ |
simon | 2:227356c7d12c | 52 | , LCD16x2B /**< 16x2 LCD panel alternate addressing */ |
simon | 2:227356c7d12c | 53 | , LCD20x2 /**< 20x2 LCD panel */ |
simon | 2:227356c7d12c | 54 | , LCD20x4 /**< 20x4 LCD panel */ |
simon | 1:ac48b187213c | 55 | }; |
simon | 1:ac48b187213c | 56 | |
simon | 2:227356c7d12c | 57 | /** Create a TextLCD interface |
simon | 2:227356c7d12c | 58 | * |
okini3939 | 9:27f430d086f3 | 59 | * @param sda I2C data line pin |
okini3939 | 9:27f430d086f3 | 60 | * @param sck I2C clock line pin |
okini3939 | 9:27f430d086f3 | 61 | * @param reset Reset pin |
simon | 2:227356c7d12c | 62 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
okini3939 | 9:27f430d086f3 | 63 | * @param addr I2C address (default = 0x74) |
simon | 2:227356c7d12c | 64 | */ |
okini3939 | 9:27f430d086f3 | 65 | PCF2119(PinName sda, PinName sck, PinName reset, LCDType type = LCD16x2, char addr = 0x74); |
okini3939 | 9:27f430d086f3 | 66 | |
okini3939 | 9:27f430d086f3 | 67 | /** Create a TextLCD interface |
okini3939 | 9:27f430d086f3 | 68 | * |
okini3939 | 9:27f430d086f3 | 69 | * @param i2c I2C class |
okini3939 | 9:27f430d086f3 | 70 | * @param reset Reset pin |
okini3939 | 9:27f430d086f3 | 71 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
okini3939 | 9:27f430d086f3 | 72 | * @param addr I2C address (default = 0x74) |
okini3939 | 9:27f430d086f3 | 73 | */ |
okini3939 | 9:27f430d086f3 | 74 | PCF2119(I2C &i2c, PinName reset, LCDType type = LCD16x2, char addr = 0x74); |
simon | 2:227356c7d12c | 75 | |
simon | 2:227356c7d12c | 76 | #if DOXYGEN_ONLY |
simon | 2:227356c7d12c | 77 | /** Write a character to the LCD |
simon | 2:227356c7d12c | 78 | * |
simon | 2:227356c7d12c | 79 | * @param c The character to write to the display |
simon | 2:227356c7d12c | 80 | */ |
simon | 2:227356c7d12c | 81 | int putc(int c); |
simon | 2:227356c7d12c | 82 | |
simon | 2:227356c7d12c | 83 | /** Write a formated string to the LCD |
simon | 2:227356c7d12c | 84 | * |
simon | 2:227356c7d12c | 85 | * @param format A printf-style format string, followed by the |
simon | 2:227356c7d12c | 86 | * variables to use in formating the string. |
simon | 2:227356c7d12c | 87 | */ |
simon | 2:227356c7d12c | 88 | int printf(const char* format, ...); |
simon | 2:227356c7d12c | 89 | #endif |
simon | 2:227356c7d12c | 90 | |
simon | 2:227356c7d12c | 91 | /** Locate to a screen column and row |
simon | 2:227356c7d12c | 92 | * |
simon | 2:227356c7d12c | 93 | * @param column The horizontal position from the left, indexed from 0 |
simon | 2:227356c7d12c | 94 | * @param row The vertical position from the top, indexed from 0 |
simon | 2:227356c7d12c | 95 | */ |
simon | 1:ac48b187213c | 96 | void locate(int column, int row); |
simon | 2:227356c7d12c | 97 | |
simon | 2:227356c7d12c | 98 | /** Clear the screen and locate to 0,0 */ |
simon | 1:ac48b187213c | 99 | void cls(); |
simon | 2:227356c7d12c | 100 | |
simon | 1:ac48b187213c | 101 | int rows(); |
simon | 2:227356c7d12c | 102 | int columns(); |
simon | 2:227356c7d12c | 103 | |
okini3939 | 9:27f430d086f3 | 104 | void cgram(int num, const char *data, int len); |
okini3939 | 9:27f430d086f3 | 105 | |
okini3939 | 9:27f430d086f3 | 106 | int raw; |
okini3939 | 9:27f430d086f3 | 107 | |
simon | 1:ac48b187213c | 108 | protected: |
simon | 1:ac48b187213c | 109 | |
simon | 1:ac48b187213c | 110 | // Stream implementation functions |
simon | 1:ac48b187213c | 111 | virtual int _putc(int value); |
simon | 1:ac48b187213c | 112 | virtual int _getc(); |
simon | 1:ac48b187213c | 113 | |
okini3939 | 9:27f430d086f3 | 114 | void init (); |
simon | 2:227356c7d12c | 115 | int address(int column, int row); |
simon | 2:227356c7d12c | 116 | void character(int column, int row, int c); |
simon | 1:ac48b187213c | 117 | void writeCommand(int command); |
simon | 1:ac48b187213c | 118 | void writeData(int data); |
okini3939 | 9:27f430d086f3 | 119 | int ascii2lcd (int c); |
simon | 1:ac48b187213c | 120 | |
okini3939 | 9:27f430d086f3 | 121 | I2C _i2c; |
okini3939 | 9:27f430d086f3 | 122 | DigitalOut _reset; |
simon | 1:ac48b187213c | 123 | LCDType _type; |
simon | 1:ac48b187213c | 124 | |
simon | 1:ac48b187213c | 125 | int _column; |
simon | 1:ac48b187213c | 126 | int _row; |
okini3939 | 9:27f430d086f3 | 127 | int _addr; |
simon | 1:ac48b187213c | 128 | }; |
simon | 1:ac48b187213c | 129 | |
simon | 1:ac48b187213c | 130 | #endif |