An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 MOD by Zak
Fork of ACM1602NI by
ACM1602NI.h@1:84527dcd3fcc, 2013-05-13 (annotated)
- Committer:
- takuo
- Date:
- Mon May 13 12:58:26 2013 +0000
- Revision:
- 1:84527dcd3fcc
- Parent:
- 0:aac87cbfc229
- Child:
- 2:6a201d126c69
Changed to Apache License (2.0)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuo | 1:84527dcd3fcc | 1 | /* An mbed Text LCD Library for Displaytronic ACM1602NI-FLW-FBW-M01 |
takuo | 1:84527dcd3fcc | 2 | * Copyright 2013, 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 | 0:aac87cbfc229 | 22 | /** An I2C Text LCD interface for driving Displaytronic ACM1602NI-FLW-FBW-M01 |
takuo | 0:aac87cbfc229 | 23 | * The interface is basically the same as TextLCD by Simon Ford. |
takuo | 0:aac87cbfc229 | 24 | * |
takuo | 0:aac87cbfc229 | 25 | * @code |
takuo | 0:aac87cbfc229 | 26 | * #include "mbed.h" |
takuo | 0:aac87cbfc229 | 27 | * #include "ACM1602NI.h" |
takuo | 0:aac87cbfc229 | 28 | * |
takuo | 0:aac87cbfc229 | 29 | * I2C i2c(p9, p10); |
takuo | 0:aac87cbfc229 | 30 | * ACM1602NI lcd(i2c); |
takuo | 0:aac87cbfc229 | 31 | * |
takuo | 0:aac87cbfc229 | 32 | * int main() { |
takuo | 0:aac87cbfc229 | 33 | * lcd.printf("Hello, World!\n"); |
takuo | 0:aac87cbfc229 | 34 | * } |
takuo | 0:aac87cbfc229 | 35 | * @endcode |
takuo | 0:aac87cbfc229 | 36 | */ |
takuo | 0:aac87cbfc229 | 37 | class ACM1602NI : public Stream |
takuo | 0:aac87cbfc229 | 38 | { |
takuo | 0:aac87cbfc229 | 39 | public: |
takuo | 0:aac87cbfc229 | 40 | /** Create an ACM1602NI object connected to the specified I2C port. |
takuo | 0:aac87cbfc229 | 41 | * |
takuo | 0:aac87cbfc229 | 42 | * @param i2c The I2C port to connect to |
takuo | 0:aac87cbfc229 | 43 | */ |
takuo | 0:aac87cbfc229 | 44 | ACM1602NI(I2C &i2c); |
takuo | 0:aac87cbfc229 | 45 | |
takuo | 0:aac87cbfc229 | 46 | /** Locate to a screen column and row |
takuo | 0:aac87cbfc229 | 47 | * |
takuo | 0:aac87cbfc229 | 48 | * @param column The horizontal position from the left, indexed from 0 |
takuo | 0:aac87cbfc229 | 49 | * @param row The vertical position from the top, indexed from 0 |
takuo | 0:aac87cbfc229 | 50 | */ |
takuo | 0:aac87cbfc229 | 51 | void locate(int column, int row); |
takuo | 0:aac87cbfc229 | 52 | |
takuo | 0:aac87cbfc229 | 53 | /** Clear the screen and locate to 0,0 */ |
takuo | 0:aac87cbfc229 | 54 | void cls(); |
takuo | 0:aac87cbfc229 | 55 | |
takuo | 0:aac87cbfc229 | 56 | int rows(); |
takuo | 0:aac87cbfc229 | 57 | int columns(); |
takuo | 0:aac87cbfc229 | 58 | |
takuo | 0:aac87cbfc229 | 59 | protected: |
takuo | 0:aac87cbfc229 | 60 | virtual int _putc(int value); |
takuo | 0:aac87cbfc229 | 61 | virtual int _getc(); |
takuo | 0:aac87cbfc229 | 62 | |
takuo | 0:aac87cbfc229 | 63 | void init(); |
takuo | 0:aac87cbfc229 | 64 | int address(int column, int raw); |
takuo | 0:aac87cbfc229 | 65 | void character(int column, int row, int c); |
takuo | 0:aac87cbfc229 | 66 | int writeBytes(const char *data, int length, bool repeated = false); |
takuo | 0:aac87cbfc229 | 67 | void writeCommand(int command); |
takuo | 0:aac87cbfc229 | 68 | void writeData(int data); |
takuo | 0:aac87cbfc229 | 69 | |
takuo | 0:aac87cbfc229 | 70 | static const int i2c_addr = 0x50 << 1; |
takuo | 0:aac87cbfc229 | 71 | static const int i2c_bit_wait_us = 20; |
takuo | 0:aac87cbfc229 | 72 | static const int i2c_command_wait_ms = 4; |
takuo | 0:aac87cbfc229 | 73 | |
takuo | 0:aac87cbfc229 | 74 | static const int display_columns = 16; |
takuo | 0:aac87cbfc229 | 75 | static const int display_rows = 2; |
takuo | 0:aac87cbfc229 | 76 | |
takuo | 0:aac87cbfc229 | 77 | I2C &_i2c; |
takuo | 0:aac87cbfc229 | 78 | int _column, _row; |
takuo | 0:aac87cbfc229 | 79 | }; |
takuo | 0:aac87cbfc229 | 80 | |
takuo | 0:aac87cbfc229 | 81 | #endif |