An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 MOD by Zak
Fork of ACM1602NI by
ACM1602NI.h@0:aac87cbfc229, 2013-05-13 (annotated)
- Committer:
- takuo
- Date:
- Mon May 13 12:50:42 2013 +0000
- Revision:
- 0:aac87cbfc229
- Child:
- 1:84527dcd3fcc
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuo | 0:aac87cbfc229 | 1 | /* mbed Text LCD Library for Displaytronic ACM1602NI-FLW-FBW-M01 |
takuo | 0:aac87cbfc229 | 2 | * Copyright (c) 2013, wtakuo |
takuo | 0:aac87cbfc229 | 3 | * |
takuo | 0:aac87cbfc229 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
takuo | 0:aac87cbfc229 | 5 | * of this software and associated documentation files (the "Software"), to deal |
takuo | 0:aac87cbfc229 | 6 | * in the Software without restriction, including without limitation the rights |
takuo | 0:aac87cbfc229 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
takuo | 0:aac87cbfc229 | 8 | * copies of the Software, and to permit persons to whom the Software is |
takuo | 0:aac87cbfc229 | 9 | * furnished to do so, subject to the following conditions: |
takuo | 0:aac87cbfc229 | 10 | * |
takuo | 0:aac87cbfc229 | 11 | * The above copyright notice and this permission notice shall be included in |
takuo | 0:aac87cbfc229 | 12 | * all copies or substantial portions of the Software. |
takuo | 0:aac87cbfc229 | 13 | * |
takuo | 0:aac87cbfc229 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
takuo | 0:aac87cbfc229 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
takuo | 0:aac87cbfc229 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
takuo | 0:aac87cbfc229 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
takuo | 0:aac87cbfc229 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
takuo | 0:aac87cbfc229 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
takuo | 0:aac87cbfc229 | 20 | * THE SOFTWARE. |
takuo | 0:aac87cbfc229 | 21 | */ |
takuo | 0:aac87cbfc229 | 22 | |
takuo | 0:aac87cbfc229 | 23 | #ifndef ACM1602NI_H |
takuo | 0:aac87cbfc229 | 24 | #define ACM1602NI_H |
takuo | 0:aac87cbfc229 | 25 | |
takuo | 0:aac87cbfc229 | 26 | #include "mbed.h" |
takuo | 0:aac87cbfc229 | 27 | |
takuo | 0:aac87cbfc229 | 28 | /** An I2C Text LCD interface for driving Displaytronic ACM1602NI-FLW-FBW-M01 |
takuo | 0:aac87cbfc229 | 29 | * The interface is basically the same as TextLCD by Simon Ford. |
takuo | 0:aac87cbfc229 | 30 | * |
takuo | 0:aac87cbfc229 | 31 | * @code |
takuo | 0:aac87cbfc229 | 32 | * #include "mbed.h" |
takuo | 0:aac87cbfc229 | 33 | * #include "ACM1602NI.h" |
takuo | 0:aac87cbfc229 | 34 | * |
takuo | 0:aac87cbfc229 | 35 | * I2C i2c(p9, p10); |
takuo | 0:aac87cbfc229 | 36 | * ACM1602NI lcd(i2c); |
takuo | 0:aac87cbfc229 | 37 | * |
takuo | 0:aac87cbfc229 | 38 | * int main() { |
takuo | 0:aac87cbfc229 | 39 | * lcd.printf("Hello, World!\n"); |
takuo | 0:aac87cbfc229 | 40 | * } |
takuo | 0:aac87cbfc229 | 41 | * @endcode |
takuo | 0:aac87cbfc229 | 42 | */ |
takuo | 0:aac87cbfc229 | 43 | class ACM1602NI : public Stream |
takuo | 0:aac87cbfc229 | 44 | { |
takuo | 0:aac87cbfc229 | 45 | public: |
takuo | 0:aac87cbfc229 | 46 | /** Create an ACM1602NI object connected to the specified I2C port. |
takuo | 0:aac87cbfc229 | 47 | * |
takuo | 0:aac87cbfc229 | 48 | * @param i2c The I2C port to connect to |
takuo | 0:aac87cbfc229 | 49 | */ |
takuo | 0:aac87cbfc229 | 50 | ACM1602NI(I2C &i2c); |
takuo | 0:aac87cbfc229 | 51 | |
takuo | 0:aac87cbfc229 | 52 | /** Locate to a screen column and row |
takuo | 0:aac87cbfc229 | 53 | * |
takuo | 0:aac87cbfc229 | 54 | * @param column The horizontal position from the left, indexed from 0 |
takuo | 0:aac87cbfc229 | 55 | * @param row The vertical position from the top, indexed from 0 |
takuo | 0:aac87cbfc229 | 56 | */ |
takuo | 0:aac87cbfc229 | 57 | void locate(int column, int row); |
takuo | 0:aac87cbfc229 | 58 | |
takuo | 0:aac87cbfc229 | 59 | /** Clear the screen and locate to 0,0 */ |
takuo | 0:aac87cbfc229 | 60 | void cls(); |
takuo | 0:aac87cbfc229 | 61 | |
takuo | 0:aac87cbfc229 | 62 | int rows(); |
takuo | 0:aac87cbfc229 | 63 | int columns(); |
takuo | 0:aac87cbfc229 | 64 | |
takuo | 0:aac87cbfc229 | 65 | protected: |
takuo | 0:aac87cbfc229 | 66 | virtual int _putc(int value); |
takuo | 0:aac87cbfc229 | 67 | virtual int _getc(); |
takuo | 0:aac87cbfc229 | 68 | |
takuo | 0:aac87cbfc229 | 69 | void init(); |
takuo | 0:aac87cbfc229 | 70 | int address(int column, int raw); |
takuo | 0:aac87cbfc229 | 71 | void character(int column, int row, int c); |
takuo | 0:aac87cbfc229 | 72 | int writeBytes(const char *data, int length, bool repeated = false); |
takuo | 0:aac87cbfc229 | 73 | void writeCommand(int command); |
takuo | 0:aac87cbfc229 | 74 | void writeData(int data); |
takuo | 0:aac87cbfc229 | 75 | |
takuo | 0:aac87cbfc229 | 76 | static const int i2c_addr = 0x50 << 1; |
takuo | 0:aac87cbfc229 | 77 | static const int i2c_bit_wait_us = 20; |
takuo | 0:aac87cbfc229 | 78 | static const int i2c_command_wait_ms = 4; |
takuo | 0:aac87cbfc229 | 79 | |
takuo | 0:aac87cbfc229 | 80 | static const int display_columns = 16; |
takuo | 0:aac87cbfc229 | 81 | static const int display_rows = 2; |
takuo | 0:aac87cbfc229 | 82 | |
takuo | 0:aac87cbfc229 | 83 | I2C &_i2c; |
takuo | 0:aac87cbfc229 | 84 | int _column, _row; |
takuo | 0:aac87cbfc229 | 85 | }; |
takuo | 0:aac87cbfc229 | 86 | |
takuo | 0:aac87cbfc229 | 87 | #endif |