An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 MOD by Zak
Fork of ACM1602NI by
ACM1602NI.h@5:c1dbbc2af9dd, 2014-01-14 (annotated)
- Committer:
- takuo
- Date:
- Tue Jan 14 02:16:15 2014 +0000
- Revision:
- 5:c1dbbc2af9dd
- Parent:
- 4:33a8ca14e0e0
- Child:
- 6:55b648ec5216
Added a constructor that takes I2C pins instead of I2C object.; The init() method is now public.
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 | 3:bac80efb323e | 2 | * Copyright 2013, 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 | 0:aac87cbfc229 | 27 | * @code |
takuo | 0:aac87cbfc229 | 28 | * #include "mbed.h" |
takuo | 0:aac87cbfc229 | 29 | * #include "ACM1602NI.h" |
takuo | 4:33a8ca14e0e0 | 30 | * |
takuo | 4:33a8ca14e0e0 | 31 | * // p9: sda, p10: scl |
takuo | 5:c1dbbc2af9dd | 32 | * ACM1602NI lcd(p9, p10); |
takuo | 0:aac87cbfc229 | 33 | * |
takuo | 0:aac87cbfc229 | 34 | * int main() { |
takuo | 0:aac87cbfc229 | 35 | * lcd.printf("Hello, World!\n"); |
takuo | 4:33a8ca14e0e0 | 36 | * lcd.printf("ACM1602NI\n"); |
takuo | 0:aac87cbfc229 | 37 | * } |
takuo | 0:aac87cbfc229 | 38 | * @endcode |
takuo | 0:aac87cbfc229 | 39 | */ |
takuo | 0:aac87cbfc229 | 40 | class ACM1602NI : public Stream |
takuo | 0:aac87cbfc229 | 41 | { |
takuo | 0:aac87cbfc229 | 42 | public: |
takuo | 5:c1dbbc2af9dd | 43 | /** Create an ACM1602NI object connected to the specified I2C pins. |
takuo | 5:c1dbbc2af9dd | 44 | * |
takuo | 5:c1dbbc2af9dd | 45 | * @parem sda The I2C data pin |
takuo | 5:c1dbbc2af9dd | 46 | * @param scl The I2C clock pin |
takuo | 5:c1dbbc2af9dd | 47 | */ |
takuo | 5:c1dbbc2af9dd | 48 | ACM1602NI(PinName sda, PinName scl); |
takuo | 5:c1dbbc2af9dd | 49 | |
takuo | 0:aac87cbfc229 | 50 | /** Create an ACM1602NI object connected to the specified I2C port. |
takuo | 0:aac87cbfc229 | 51 | * |
takuo | 5:c1dbbc2af9dd | 52 | * @param i2c The I2C port to connect to |
takuo | 0:aac87cbfc229 | 53 | */ |
takuo | 0:aac87cbfc229 | 54 | ACM1602NI(I2C &i2c); |
takuo | 0:aac87cbfc229 | 55 | |
takuo | 5:c1dbbc2af9dd | 56 | /** Initialize the device and clear screen |
takuo | 5:c1dbbc2af9dd | 57 | */ |
takuo | 5:c1dbbc2af9dd | 58 | void init(); |
takuo | 5:c1dbbc2af9dd | 59 | |
takuo | 0:aac87cbfc229 | 60 | /** Locate to a screen column and row |
takuo | 0:aac87cbfc229 | 61 | * |
takuo | 0:aac87cbfc229 | 62 | * @param column The horizontal position from the left, indexed from 0 |
takuo | 0:aac87cbfc229 | 63 | * @param row The vertical position from the top, indexed from 0 |
takuo | 0:aac87cbfc229 | 64 | */ |
takuo | 0:aac87cbfc229 | 65 | void locate(int column, int row); |
takuo | 5:c1dbbc2af9dd | 66 | |
takuo | 0:aac87cbfc229 | 67 | /** Clear the screen and locate to 0,0 */ |
takuo | 0:aac87cbfc229 | 68 | void cls(); |
takuo | 0:aac87cbfc229 | 69 | |
takuo | 0:aac87cbfc229 | 70 | int rows(); |
takuo | 0:aac87cbfc229 | 71 | int columns(); |
takuo | 0:aac87cbfc229 | 72 | |
takuo | 0:aac87cbfc229 | 73 | protected: |
takuo | 0:aac87cbfc229 | 74 | virtual int _putc(int value); |
takuo | 0:aac87cbfc229 | 75 | virtual int _getc(); |
takuo | 0:aac87cbfc229 | 76 | |
takuo | 0:aac87cbfc229 | 77 | int address(int column, int raw); |
takuo | 0:aac87cbfc229 | 78 | void character(int column, int row, int c); |
takuo | 0:aac87cbfc229 | 79 | int writeBytes(const char *data, int length, bool repeated = false); |
takuo | 0:aac87cbfc229 | 80 | void writeCommand(int command); |
takuo | 0:aac87cbfc229 | 81 | void writeData(int data); |
takuo | 0:aac87cbfc229 | 82 | |
takuo | 0:aac87cbfc229 | 83 | static const int i2c_addr = 0x50 << 1; |
takuo | 0:aac87cbfc229 | 84 | static const int i2c_bit_wait_us = 20; |
takuo | 0:aac87cbfc229 | 85 | static const int i2c_command_wait_ms = 4; |
takuo | 0:aac87cbfc229 | 86 | |
takuo | 0:aac87cbfc229 | 87 | static const int display_columns = 16; |
takuo | 0:aac87cbfc229 | 88 | static const int display_rows = 2; |
takuo | 0:aac87cbfc229 | 89 | |
takuo | 5:c1dbbc2af9dd | 90 | I2C _i2c; |
takuo | 0:aac87cbfc229 | 91 | int _column, _row; |
takuo | 0:aac87cbfc229 | 92 | }; |
takuo | 0:aac87cbfc229 | 93 | |
takuo | 0:aac87cbfc229 | 94 | #endif |