An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 MOD by Zak
Fork of ACM1602NI by
ACM1602NI.h@7:728c03b52b79, 2014-01-18 (annotated)
- Committer:
- takuo
- Date:
- Sat Jan 18 02:27:30 2014 +0000
- Revision:
- 7:728c03b52b79
- Parent:
- 6:55b648ec5216
- Child:
- 8:661827681a12
Revised the documents
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuo | 3:bac80efb323e | 1 | /* An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 |
takuo | 7:728c03b52b79 | 2 | * Copyright 2013, 2014, Takuo WATANABE (wtakuo) |
takuo | 0:aac87cbfc229 | 3 | * |
takuo | 1:84527dcd3fcc | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
takuo | 1:84527dcd3fcc | 5 | * you may not use this file except in compliance with the License. |
takuo | 1:84527dcd3fcc | 6 | * You may obtain a copy of the License at |
takuo | 0:aac87cbfc229 | 7 | * |
takuo | 1:84527dcd3fcc | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
takuo | 0:aac87cbfc229 | 9 | * |
takuo | 1:84527dcd3fcc | 10 | * Unless required by applicable law or agreed to in writing, software |
takuo | 1:84527dcd3fcc | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
takuo | 1:84527dcd3fcc | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
takuo | 1:84527dcd3fcc | 13 | * See the License for the specific language governing permissions and |
takuo | 1:84527dcd3fcc | 14 | * limitations under the License. |
takuo | 0:aac87cbfc229 | 15 | */ |
takuo | 1:84527dcd3fcc | 16 | |
takuo | 0:aac87cbfc229 | 17 | #ifndef ACM1602NI_H |
takuo | 0:aac87cbfc229 | 18 | #define ACM1602NI_H |
takuo | 0:aac87cbfc229 | 19 | |
takuo | 0:aac87cbfc229 | 20 | #include "mbed.h" |
takuo | 0:aac87cbfc229 | 21 | |
takuo | 3:bac80efb323e | 22 | /** An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01. |
takuo | 4:33a8ca14e0e0 | 23 | * The device does not work with default I2C library due to its slow I2C responce. |
takuo | 4:33a8ca14e0e0 | 24 | * This library adds some extra waits so that the device can answer to the I2C commands. |
takuo | 0:aac87cbfc229 | 25 | * The interface is basically the same as TextLCD by Simon Ford. |
takuo | 0:aac87cbfc229 | 26 | * |
takuo | 7:728c03b52b79 | 27 | * Example: |
takuo | 0:aac87cbfc229 | 28 | * @code |
takuo | 0:aac87cbfc229 | 29 | * #include "mbed.h" |
takuo | 7:728c03b52b79 | 30 | * |
takuo | 7:728c03b52b79 | 31 | * // I2C Text LCD: http://mbed.org/users/takuo/code/ACM1602NI/ |
takuo | 0:aac87cbfc229 | 32 | * #include "ACM1602NI.h" |
takuo | 4:33a8ca14e0e0 | 33 | * |
takuo | 7:728c03b52b79 | 34 | * // I2C pins: p9 = sda, p10 = scl |
takuo | 5:c1dbbc2af9dd | 35 | * ACM1602NI lcd(p9, p10); |
takuo | 0:aac87cbfc229 | 36 | * |
takuo | 7:728c03b52b79 | 37 | * // You can specify an I2C object instead. |
takuo | 7:728c03b52b79 | 38 | * // I2C i2c(p9, p10); |
takuo | 7:728c03b52b79 | 39 | * // ACM1602NI lcd(i2c); |
takuo | 7:728c03b52b79 | 40 | * |
takuo | 7:728c03b52b79 | 41 | * int main() |
takuo | 7:728c03b52b79 | 42 | * { |
takuo | 0:aac87cbfc229 | 43 | * lcd.printf("Hello, World!\n"); |
takuo | 4:33a8ca14e0e0 | 44 | * lcd.printf("ACM1602NI\n"); |
takuo | 0:aac87cbfc229 | 45 | * } |
takuo | 0:aac87cbfc229 | 46 | * @endcode |
takuo | 0:aac87cbfc229 | 47 | */ |
takuo | 0:aac87cbfc229 | 48 | class ACM1602NI : public Stream |
takuo | 0:aac87cbfc229 | 49 | { |
takuo | 0:aac87cbfc229 | 50 | public: |
takuo | 5:c1dbbc2af9dd | 51 | /** Create an ACM1602NI object connected to the specified I2C pins. |
takuo | 5:c1dbbc2af9dd | 52 | * |
takuo | 7:728c03b52b79 | 53 | * @param sda I2C data pin |
takuo | 7:728c03b52b79 | 54 | * @param scl I2C clock pin |
takuo | 5:c1dbbc2af9dd | 55 | */ |
takuo | 5:c1dbbc2af9dd | 56 | ACM1602NI(PinName sda, PinName scl); |
takuo | 5:c1dbbc2af9dd | 57 | |
takuo | 0:aac87cbfc229 | 58 | /** Create an ACM1602NI object connected to the specified I2C port. |
takuo | 0:aac87cbfc229 | 59 | * |
takuo | 7:728c03b52b79 | 60 | * @param i2c I2C port |
takuo | 0:aac87cbfc229 | 61 | */ |
takuo | 0:aac87cbfc229 | 62 | ACM1602NI(I2C &i2c); |
takuo | 0:aac87cbfc229 | 63 | |
takuo | 5:c1dbbc2af9dd | 64 | /** Initialize the device and clear screen |
takuo | 5:c1dbbc2af9dd | 65 | */ |
takuo | 5:c1dbbc2af9dd | 66 | void init(); |
takuo | 5:c1dbbc2af9dd | 67 | |
takuo | 0:aac87cbfc229 | 68 | /** Locate to a screen column and row |
takuo | 0:aac87cbfc229 | 69 | * |
takuo | 0:aac87cbfc229 | 70 | * @param column The horizontal position from the left, indexed from 0 |
takuo | 0:aac87cbfc229 | 71 | * @param row The vertical position from the top, indexed from 0 |
takuo | 0:aac87cbfc229 | 72 | */ |
takuo | 0:aac87cbfc229 | 73 | void locate(int column, int row); |
takuo | 5:c1dbbc2af9dd | 74 | |
takuo | 0:aac87cbfc229 | 75 | /** Clear the screen and locate to 0,0 */ |
takuo | 0:aac87cbfc229 | 76 | void cls(); |
takuo | 0:aac87cbfc229 | 77 | |
takuo | 0:aac87cbfc229 | 78 | int rows(); |
takuo | 0:aac87cbfc229 | 79 | int columns(); |
takuo | 0:aac87cbfc229 | 80 | |
takuo | 0:aac87cbfc229 | 81 | protected: |
takuo | 0:aac87cbfc229 | 82 | static const int i2c_addr = 0x50 << 1; |
takuo | 0:aac87cbfc229 | 83 | static const int i2c_bit_wait_us = 20; |
takuo | 0:aac87cbfc229 | 84 | static const int i2c_command_wait_ms = 4; |
takuo | 0:aac87cbfc229 | 85 | |
takuo | 0:aac87cbfc229 | 86 | static const int display_columns = 16; |
takuo | 0:aac87cbfc229 | 87 | static const int display_rows = 2; |
takuo | 0:aac87cbfc229 | 88 | |
takuo | 5:c1dbbc2af9dd | 89 | I2C _i2c; |
takuo | 0:aac87cbfc229 | 90 | int _column, _row; |
takuo | 7:728c03b52b79 | 91 | |
takuo | 7:728c03b52b79 | 92 | virtual int _putc(int value); |
takuo | 7:728c03b52b79 | 93 | virtual int _getc(); |
takuo | 7:728c03b52b79 | 94 | |
takuo | 7:728c03b52b79 | 95 | int address(int column, int raw); |
takuo | 7:728c03b52b79 | 96 | void character(int column, int row, int c); |
takuo | 7:728c03b52b79 | 97 | int writeBytes(const char *data, int length, bool repeated = false); |
takuo | 7:728c03b52b79 | 98 | void writeCommand(int command); |
takuo | 7:728c03b52b79 | 99 | void writeData(int data); |
takuo | 0:aac87cbfc229 | 100 | }; |
takuo | 0:aac87cbfc229 | 101 | |
takuo | 0:aac87cbfc229 | 102 | #endif |