秋月電子 I2C接続キャラクタLCDモジュール用にI2CLCDライブラリを修正しました。 Modified I2CLCD Lib for ACM1602NI character LCD module. http://akizukidenshi.com/catalog/g/gP-05693/

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
maro
Date:
Sun Oct 20 03:44:57 2013 +0000
Commit message:
Changed the waiting time of writeCommand and writeData

Changed in this revision

I2cLCD16_ACM1601NI/I2cLCD.cpp Show annotated file Show diff for this revision Revisions of this file
I2cLCD16_ACM1601NI/I2cLCD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9bf010140a3f I2cLCD16_ACM1601NI/I2cLCD.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2cLCD16_ACM1601NI/I2cLCD.cpp	Sun Oct 20 03:44:57 2013 +0000
@@ -0,0 +1,120 @@
+//8x2 lcd
+#include "I2cLCD.h"
+#include "mbed.h"
+
+#define    I2CLCD_ADDR    0xa0//0x7C
+
+#define RS_CMD        0x00
+#define RS_DATA       0x80
+const short WAIT1 = 10;
+
+I2cLCD::I2cLCD(PinName sda, PinName scl) :  _i2c( sda , scl ){
+    //_i2c.frequency(50000);
+    wait_ms(15);
+    writeCommand(0x01);
+    wait_ms(5);
+    writeCommand(0x38);
+    wait_ms(5);
+    writeCommand(0x0f);
+    wait_ms(5);
+    writeCommand(0x06);
+    wait_ms(5);
+    writeCommand(0x0c);
+    wait_ms(5);       
+}
+
+
+
+void I2cLCD::character(int column, int row, int c) {
+    int a = address(column, row);
+    writeCommand(a);
+    writeData(c);
+}
+
+void I2cLCD::cls() {
+    writeCommand(0x01); // cls, and set cursor to 0
+    wait_ms(2);
+    locate(0, 0);
+}
+
+void I2cLCD::locate(int column, int row) {
+    _column = column;
+    _row = row;
+}
+
+int I2cLCD::_putc(int value) {
+    if (value == '\n') {
+        _column = 0;
+        _row++;
+        if (_row >= rows()) {
+            _row = 0;
+        }
+    } else {
+        character(_column, _row, value);
+        _column++;
+        if (_column >= columns()) {
+            _column = 0;
+            _row++;
+            if (_row >= rows()) {
+                _row = 0;
+            }
+        }
+    }
+    return value;
+}
+
+int I2cLCD::_getc() {
+    return -1;
+}
+
+void I2cLCD::writeCommand( int cmd )
+{
+    char cmds[2];
+    
+    cmds[0] = RS_CMD;
+    cmds[1] = cmd;
+    
+    //_i2c.write(I2CLCD_ADDR, cmds, 2);
+	_i2c.start();
+	wait_us(9);
+    _i2c.write(I2CLCD_ADDR);
+	wait_us(WAIT1);
+	_i2c.write(cmds[0]);
+	wait_us(WAIT1);	
+	_i2c.write(cmds[1]);
+	wait_us(WAIT1);	
+	_i2c.stop();
+}
+
+void I2cLCD::writeData( int data )
+{
+    char cmd[2];
+    
+    cmd[0] = RS_DATA;
+    cmd[1] = data;
+    
+    //_i2c.write(I2CLCD_ADDR, cmd, 2);
+	_i2c.start();
+	wait_us(9);
+    _i2c.write(I2CLCD_ADDR);
+	wait_us(WAIT1);	
+	_i2c.write(cmd[0]);
+	wait_us(WAIT1);	
+	_i2c.write(cmd[1]);
+	wait_us(WAIT1);	
+	_i2c.stop();
+
+}
+
+int I2cLCD::address(int column, int row) {
+
+    return 0x80 + (row * 0x40) + column;
+}
+
+int I2cLCD::columns() {
+    return 16;
+}
+
+int I2cLCD::rows() {
+    return 2;
+}
diff -r 000000000000 -r 9bf010140a3f I2cLCD16_ACM1601NI/I2cLCD.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2cLCD16_ACM1601NI/I2cLCD.h	Sun Oct 20 03:44:57 2013 +0000
@@ -0,0 +1,40 @@
+//8x2 lcd
+#ifndef MBED_I2CLCD_H
+#define MBED_I2CLCD_H
+
+#include "mbed.h"
+
+class I2cLCD : public Stream {
+public:
+
+    I2cLCD(PinName sda, PinName scl);
+#if DOXYGEN_ONLY
+    int putc(int c);
+    int printf(const char* format, ...);
+#endif
+    void locate(int column, int row);
+    void cls();
+    int rows();
+    int columns();
+    void puticon(int flg);
+    
+protected:
+    virtual int _putc(int value);
+    virtual int _getc();
+
+    int address(int column, int row);
+    void character(int column, int row, int c);
+    void writeCommand( int cmd );
+    void writeData( int data );
+    
+    //DigitalOut _rs;
+    I2C    _i2c;
+    int _column;
+    int _row;
+    
+    char contrast;
+    int icon;
+    
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9bf010140a3f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 20 03:44:57 2013 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+#include "I2cLCD.h"
+I2cLCD lcd(p28, p27);              // sda scl
+
+int main() {
+    lcd.locate(0,0);
+    lcd.printf("I2C_LCD");
+    lcd.locate(0,1);
+    lcd.printf("ABCdefghij");
+    
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
diff -r 000000000000 -r 9bf010140a3f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 20 03:44:57 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file