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

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

Files at this revision

API Documentation at this revision

Comitter:
takuo
Date:
Sat Feb 15 13:48:55 2014 +0000
Parent:
7:728c03b52b79
Commit message:
Revised the documents

Changed in this revision

ACM1602NI.cpp Show annotated file Show diff for this revision Revisions of this file
ACM1602NI.h Show annotated file Show diff for this revision Revisions of this file
--- a/ACM1602NI.cpp	Sat Jan 18 02:27:30 2014 +0000
+++ b/ACM1602NI.cpp	Sat Feb 15 13:48:55 2014 +0000
@@ -20,18 +20,15 @@
 #define I2C_SUCCESS 0
 #define I2C_FAILURE 1
 
-ACM1602NI::ACM1602NI(PinName sda, PinName scl) : _i2c(sda, scl)
-{
+ACM1602NI::ACM1602NI(PinName sda, PinName scl) : _i2c(sda, scl) {
     init();
 }
 
-ACM1602NI::ACM1602NI(I2C &i2c) : _i2c(i2c)
-{
+ACM1602NI::ACM1602NI(I2C &i2c) : _i2c(i2c) {
     init();
 }
 
-void ACM1602NI::init()
-{
+void ACM1602NI::init() {
     writeCommand(0x01);
     wait_ms(i2c_command_wait_ms);
     writeCommand(0x38);
@@ -43,8 +40,7 @@
     locate(0, 0);
 }
 
-int ACM1602NI::writeBytes(const char *data, int length, bool repeated)
-{
+int ACM1602NI::writeBytes(const char *data, int length, bool repeated) {
     wait_us(i2c_bit_wait_us);
     _i2c.start();
     for (int i = 0; i < length; i++) {
@@ -62,31 +58,28 @@
     return I2C_SUCCESS;
 }
 
-void ACM1602NI::character(int column, int row, int c)
-{
+void ACM1602NI::character(int column, int row, int c) {
     writeCommand(address(column, row));
     writeData(c);
 }
 
-void ACM1602NI::cls()
-{
+void ACM1602NI::cls() {
     writeCommand(0x01);
     wait_ms(i2c_command_wait_ms);
     locate(0, 0);
 }
 
-void ACM1602NI::locate(int column, int row)
-{
+void ACM1602NI::locate(int column, int row) {
     _column = column;
     _row = row;
 }
 
-int ACM1602NI::_putc(int value)
-{
+int ACM1602NI::_putc(int value) {
     if (value == '\n') {
         _column = 0;
         _row = (_row + 1) % rows();
-    } else {
+    }
+    else {
         character(_column, _row, value);
         _column++;
         if (_column >= columns()) {
@@ -97,34 +90,28 @@
     return value;
 }
 
-int ACM1602NI::_getc()
-{
+int ACM1602NI::_getc() {
     return -1;
 }
 
-void ACM1602NI::writeCommand(int command)
-{
+void ACM1602NI::writeCommand(char command) {
     char bs[3] = { i2c_addr, 0x00, command };
     writeBytes(bs, 3);
 }
 
-void ACM1602NI::writeData(int data)
-{
+void ACM1602NI::writeData(char data) {
     char bs[3] = { i2c_addr, 0x80, data };
     writeBytes(bs, 3);
 }
 
-int ACM1602NI::address(int column, int row)
-{
+int ACM1602NI::address(int column, int row) {
     return 0x80 + row * 0x40 + column;
 }
 
-int ACM1602NI::columns()
-{
+int ACM1602NI::columns() {
     return display_columns;
 }
 
-int ACM1602NI::rows()
-{
+int ACM1602NI::rows() {
     return display_rows;
 }
--- a/ACM1602NI.h	Sat Jan 18 02:27:30 2014 +0000
+++ b/ACM1602NI.h	Sat Feb 15 13:48:55 2014 +0000
@@ -23,12 +23,15 @@
  * The device does not work with default I2C library due to its slow I2C responce.
  * This library adds some extra waits so that the device can answer to the I2C commands.
  * The interface is basically the same as TextLCD by Simon Ford.
+ * 
+ * This LCD device is manufactured by Xiamen Zettler Electronics Co. Ltd. and distributed by
+ * Akizuki Denshi Tsusho Co. Ltd.
+ * http://akizukidenshi.com/catalog/g/gP-05693/
+ * http://akizukidenshi.com/download/ds/xiamen/ACM1602NI-FLW-FBW-M01_DISPLAYTRONIC_%20SPEC%20VER1.2.pdf
  *
  * Example:
  * @code
  * #include "mbed.h"
- *
- * // I2C Text LCD: http://mbed.org/users/takuo/code/ACM1602NI/
  * #include "ACM1602NI.h"
  *
  * // I2C pins: p9 = sda, p10 = scl
@@ -38,15 +41,13 @@
  * // I2C i2c(p9, p10);
  * // ACM1602NI lcd(i2c);
  *
- * int main()
- * {
+ * int main() {
  *     lcd.printf("Hello, World!\n");
  *     lcd.printf("ACM1602NI\n");
  * }
  * @endcode
  */
-class ACM1602NI : public Stream
-{
+class ACM1602NI : public Stream {
 public:
     /** Create an ACM1602NI object connected to the specified I2C pins.
      *
@@ -78,6 +79,21 @@
     int rows();
     int columns();
 
+#if DOXYGEN_ONLY
+    /** Write a character to the LCD
+     *
+     * @param c The character to write to the display
+     */
+    int putc(int c);
+
+    /** Write a formated string to the LCD
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formating the string.
+     */
+    int printf(const char* format, ...);
+#endif
+
 protected:
     static const int i2c_addr = 0x50 << 1;
     static const int i2c_bit_wait_us = 20;
@@ -94,9 +110,10 @@
 
     int address(int column, int raw);
     void character(int column, int row, int c);
+
     int writeBytes(const char *data, int length, bool repeated = false);
-    void writeCommand(int command);
-    void writeData(int data);
+    void writeCommand(char command);
+    void writeData(char data);
 };
 
 #endif