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 Feb 15 13:48:55 2014 +0000
Revision:
8:661827681a12
Parent:
7:728c03b52b79
Revised 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 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 8:661827681a12 26 *
takuo 8:661827681a12 27 * This LCD device is manufactured by Xiamen Zettler Electronics Co. Ltd. and distributed by
takuo 8:661827681a12 28 * Akizuki Denshi Tsusho Co. Ltd.
takuo 8:661827681a12 29 * http://akizukidenshi.com/catalog/g/gP-05693/
takuo 8:661827681a12 30 * http://akizukidenshi.com/download/ds/xiamen/ACM1602NI-FLW-FBW-M01_DISPLAYTRONIC_%20SPEC%20VER1.2.pdf
takuo 0:aac87cbfc229 31 *
takuo 7:728c03b52b79 32 * Example:
takuo 0:aac87cbfc229 33 * @code
takuo 0:aac87cbfc229 34 * #include "mbed.h"
takuo 0:aac87cbfc229 35 * #include "ACM1602NI.h"
takuo 4:33a8ca14e0e0 36 *
takuo 7:728c03b52b79 37 * // I2C pins: p9 = sda, p10 = scl
takuo 5:c1dbbc2af9dd 38 * ACM1602NI lcd(p9, p10);
takuo 0:aac87cbfc229 39 *
takuo 7:728c03b52b79 40 * // You can specify an I2C object instead.
takuo 7:728c03b52b79 41 * // I2C i2c(p9, p10);
takuo 7:728c03b52b79 42 * // ACM1602NI lcd(i2c);
takuo 7:728c03b52b79 43 *
takuo 8:661827681a12 44 * int main() {
takuo 0:aac87cbfc229 45 * lcd.printf("Hello, World!\n");
takuo 4:33a8ca14e0e0 46 * lcd.printf("ACM1602NI\n");
takuo 0:aac87cbfc229 47 * }
takuo 0:aac87cbfc229 48 * @endcode
takuo 0:aac87cbfc229 49 */
takuo 8:661827681a12 50 class ACM1602NI : public Stream {
takuo 0:aac87cbfc229 51 public:
takuo 5:c1dbbc2af9dd 52 /** Create an ACM1602NI object connected to the specified I2C pins.
takuo 5:c1dbbc2af9dd 53 *
takuo 7:728c03b52b79 54 * @param sda I2C data pin
takuo 7:728c03b52b79 55 * @param scl I2C clock pin
takuo 5:c1dbbc2af9dd 56 */
takuo 5:c1dbbc2af9dd 57 ACM1602NI(PinName sda, PinName scl);
takuo 5:c1dbbc2af9dd 58
takuo 0:aac87cbfc229 59 /** Create an ACM1602NI object connected to the specified I2C port.
takuo 0:aac87cbfc229 60 *
takuo 7:728c03b52b79 61 * @param i2c I2C port
takuo 0:aac87cbfc229 62 */
takuo 0:aac87cbfc229 63 ACM1602NI(I2C &i2c);
takuo 0:aac87cbfc229 64
takuo 5:c1dbbc2af9dd 65 /** Initialize the device and clear screen
takuo 5:c1dbbc2af9dd 66 */
takuo 5:c1dbbc2af9dd 67 void init();
takuo 5:c1dbbc2af9dd 68
takuo 0:aac87cbfc229 69 /** Locate to a screen column and row
takuo 0:aac87cbfc229 70 *
takuo 0:aac87cbfc229 71 * @param column The horizontal position from the left, indexed from 0
takuo 0:aac87cbfc229 72 * @param row The vertical position from the top, indexed from 0
takuo 0:aac87cbfc229 73 */
takuo 0:aac87cbfc229 74 void locate(int column, int row);
takuo 5:c1dbbc2af9dd 75
takuo 0:aac87cbfc229 76 /** Clear the screen and locate to 0,0 */
takuo 0:aac87cbfc229 77 void cls();
takuo 0:aac87cbfc229 78
takuo 0:aac87cbfc229 79 int rows();
takuo 0:aac87cbfc229 80 int columns();
takuo 0:aac87cbfc229 81
takuo 8:661827681a12 82 #if DOXYGEN_ONLY
takuo 8:661827681a12 83 /** Write a character to the LCD
takuo 8:661827681a12 84 *
takuo 8:661827681a12 85 * @param c The character to write to the display
takuo 8:661827681a12 86 */
takuo 8:661827681a12 87 int putc(int c);
takuo 8:661827681a12 88
takuo 8:661827681a12 89 /** Write a formated string to the LCD
takuo 8:661827681a12 90 *
takuo 8:661827681a12 91 * @param format A printf-style format string, followed by the
takuo 8:661827681a12 92 * variables to use in formating the string.
takuo 8:661827681a12 93 */
takuo 8:661827681a12 94 int printf(const char* format, ...);
takuo 8:661827681a12 95 #endif
takuo 8:661827681a12 96
takuo 0:aac87cbfc229 97 protected:
takuo 0:aac87cbfc229 98 static const int i2c_addr = 0x50 << 1;
takuo 0:aac87cbfc229 99 static const int i2c_bit_wait_us = 20;
takuo 0:aac87cbfc229 100 static const int i2c_command_wait_ms = 4;
takuo 0:aac87cbfc229 101
takuo 0:aac87cbfc229 102 static const int display_columns = 16;
takuo 0:aac87cbfc229 103 static const int display_rows = 2;
takuo 0:aac87cbfc229 104
takuo 5:c1dbbc2af9dd 105 I2C _i2c;
takuo 0:aac87cbfc229 106 int _column, _row;
takuo 7:728c03b52b79 107
takuo 7:728c03b52b79 108 virtual int _putc(int value);
takuo 7:728c03b52b79 109 virtual int _getc();
takuo 7:728c03b52b79 110
takuo 7:728c03b52b79 111 int address(int column, int raw);
takuo 7:728c03b52b79 112 void character(int column, int row, int c);
takuo 8:661827681a12 113
takuo 7:728c03b52b79 114 int writeBytes(const char *data, int length, bool repeated = false);
takuo 8:661827681a12 115 void writeCommand(char command);
takuo 8:661827681a12 116 void writeData(char data);
takuo 0:aac87cbfc229 117 };
takuo 0:aac87cbfc229 118
takuo 0:aac87cbfc229 119 #endif