An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01

Dependents:   ACM1602NI_Demo ROBOT_v01 ROBOT_v02 Boku-Transmit ... more

Committer:
takuo
Date:
Sat Dec 14 14:45:38 2013 +0000
Revision:
4:33a8ca14e0e0
Parent:
3:bac80efb323e
Child:
5:c1dbbc2af9dd
Fixed the documents

Who changed what in which revision?

UserRevisionLine numberNew 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 0:aac87cbfc229 32 * I2C i2c(p9, p10);
takuo 0:aac87cbfc229 33 * ACM1602NI lcd(i2c);
takuo 0:aac87cbfc229 34 *
takuo 0:aac87cbfc229 35 * int main() {
takuo 0:aac87cbfc229 36 * lcd.printf("Hello, World!\n");
takuo 4:33a8ca14e0e0 37 * lcd.printf("ACM1602NI\n");
takuo 0:aac87cbfc229 38 * }
takuo 0:aac87cbfc229 39 * @endcode
takuo 0:aac87cbfc229 40 */
takuo 0:aac87cbfc229 41 class ACM1602NI : public Stream
takuo 0:aac87cbfc229 42 {
takuo 0:aac87cbfc229 43 public:
takuo 0:aac87cbfc229 44 /** Create an ACM1602NI object connected to the specified I2C port.
takuo 0:aac87cbfc229 45 *
takuo 0:aac87cbfc229 46 * @param i2c The I2C port to connect to
takuo 0:aac87cbfc229 47 */
takuo 0:aac87cbfc229 48 ACM1602NI(I2C &i2c);
takuo 0:aac87cbfc229 49
takuo 0:aac87cbfc229 50 /** Locate to a screen column and row
takuo 0:aac87cbfc229 51 *
takuo 0:aac87cbfc229 52 * @param column The horizontal position from the left, indexed from 0
takuo 0:aac87cbfc229 53 * @param row The vertical position from the top, indexed from 0
takuo 0:aac87cbfc229 54 */
takuo 0:aac87cbfc229 55 void locate(int column, int row);
takuo 0:aac87cbfc229 56
takuo 0:aac87cbfc229 57 /** Clear the screen and locate to 0,0 */
takuo 0:aac87cbfc229 58 void cls();
takuo 0:aac87cbfc229 59
takuo 0:aac87cbfc229 60 int rows();
takuo 0:aac87cbfc229 61 int columns();
takuo 0:aac87cbfc229 62
takuo 0:aac87cbfc229 63 protected:
takuo 0:aac87cbfc229 64 virtual int _putc(int value);
takuo 0:aac87cbfc229 65 virtual int _getc();
takuo 0:aac87cbfc229 66
takuo 0:aac87cbfc229 67 void init();
takuo 0:aac87cbfc229 68 int address(int column, int raw);
takuo 0:aac87cbfc229 69 void character(int column, int row, int c);
takuo 0:aac87cbfc229 70 int writeBytes(const char *data, int length, bool repeated = false);
takuo 0:aac87cbfc229 71 void writeCommand(int command);
takuo 0:aac87cbfc229 72 void writeData(int data);
takuo 0:aac87cbfc229 73
takuo 0:aac87cbfc229 74 static const int i2c_addr = 0x50 << 1;
takuo 0:aac87cbfc229 75 static const int i2c_bit_wait_us = 20;
takuo 0:aac87cbfc229 76 static const int i2c_command_wait_ms = 4;
takuo 0:aac87cbfc229 77
takuo 0:aac87cbfc229 78 static const int display_columns = 16;
takuo 0:aac87cbfc229 79 static const int display_rows = 2;
takuo 0:aac87cbfc229 80
takuo 0:aac87cbfc229 81 I2C &_i2c;
takuo 0:aac87cbfc229 82 int _column, _row;
takuo 0:aac87cbfc229 83 };
takuo 0:aac87cbfc229 84
takuo 0:aac87cbfc229 85 #endif