An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01
Dependents: ACM1602NI_Demo ROBOT_v01 ROBOT_v02 Boku-Transmit ... more
ACM1602NI.h
00001 /* An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01 00002 * Copyright 2013, 2014, Takuo WATANABE (wtakuo) 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ACM1602NI_H 00018 #define ACM1602NI_H 00019 00020 #include "mbed.h" 00021 00022 /** An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01. 00023 * The device does not work with default I2C library due to its slow I2C responce. 00024 * This library adds some extra waits so that the device can answer to the I2C commands. 00025 * The interface is basically the same as TextLCD by Simon Ford. 00026 * 00027 * This LCD device is manufactured by Xiamen Zettler Electronics Co. Ltd. and distributed by 00028 * Akizuki Denshi Tsusho Co. Ltd. 00029 * http://akizukidenshi.com/catalog/g/gP-05693/ 00030 * http://akizukidenshi.com/download/ds/xiamen/ACM1602NI-FLW-FBW-M01_DISPLAYTRONIC_%20SPEC%20VER1.2.pdf 00031 * 00032 * Example: 00033 * @code 00034 * #include "mbed.h" 00035 * #include "ACM1602NI.h" 00036 * 00037 * // I2C pins: p9 = sda, p10 = scl 00038 * ACM1602NI lcd(p9, p10); 00039 * 00040 * // You can specify an I2C object instead. 00041 * // I2C i2c(p9, p10); 00042 * // ACM1602NI lcd(i2c); 00043 * 00044 * int main() { 00045 * lcd.printf("Hello, World!\n"); 00046 * lcd.printf("ACM1602NI\n"); 00047 * } 00048 * @endcode 00049 */ 00050 class ACM1602NI : public Stream { 00051 public: 00052 /** Create an ACM1602NI object connected to the specified I2C pins. 00053 * 00054 * @param sda I2C data pin 00055 * @param scl I2C clock pin 00056 */ 00057 ACM1602NI(PinName sda, PinName scl); 00058 00059 /** Create an ACM1602NI object connected to the specified I2C port. 00060 * 00061 * @param i2c I2C port 00062 */ 00063 ACM1602NI(I2C &i2c); 00064 00065 /** Initialize the device and clear screen 00066 */ 00067 void init(); 00068 00069 /** Locate to a screen column and row 00070 * 00071 * @param column The horizontal position from the left, indexed from 0 00072 * @param row The vertical position from the top, indexed from 0 00073 */ 00074 void locate(int column, int row); 00075 00076 /** Clear the screen and locate to 0,0 */ 00077 void cls(); 00078 00079 int rows(); 00080 int columns(); 00081 00082 #if DOXYGEN_ONLY 00083 /** Write a character to the LCD 00084 * 00085 * @param c The character to write to the display 00086 */ 00087 int putc(int c); 00088 00089 /** Write a formated string to the LCD 00090 * 00091 * @param format A printf-style format string, followed by the 00092 * variables to use in formating the string. 00093 */ 00094 int printf(const char* format, ...); 00095 #endif 00096 00097 protected: 00098 static const int i2c_addr = 0x50 << 1; 00099 static const int i2c_bit_wait_us = 20; 00100 static const int i2c_command_wait_ms = 4; 00101 00102 static const int display_columns = 16; 00103 static const int display_rows = 2; 00104 00105 I2C _i2c; 00106 int _column, _row; 00107 00108 virtual int _putc(int value); 00109 virtual int _getc(); 00110 00111 int address(int column, int raw); 00112 void character(int column, int row, int c); 00113 00114 int writeBytes(const char *data, int length, bool repeated = false); 00115 void writeCommand(char command); 00116 void writeData(char data); 00117 }; 00118 00119 #endif
Generated on Tue Jul 12 2022 18:38:34 by 1.7.2