Dependencies:   mbed

Fork of I2CTextLCD by Romilly Cocking

Files at this revision

API Documentation at this revision

Comitter:
inggrig
Date:
Fri Apr 06 09:33:48 2018 +0000
Parent:
0:6beb6f498640
Commit message:
Library for I2C Lcd 16x2 with china 1? I2C module

Changed in this revision

TextLCD.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.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 6beb6f498640 -r 3561ca8c9754 TextLCD.cpp
--- a/TextLCD.cpp	Mon Aug 09 14:17:02 2010 +0000
+++ b/TextLCD.cpp	Fri Apr 06 09:33:48 2018 +0000
@@ -54,19 +54,22 @@
 TextLCD::TextLCD(PinName sda, PinName scl, int i2cAddress, LCDType type) : _i2c(sda, scl),
         _type(type) {
     _i2cAddress = i2cAddress;
-    wait(0.015);        // Wait 15ms to ensure powered up
+    wait(0.020);        // Wait 15ms to ensure powered up
 
     // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
     for (int i=0; i<3; i++) {
-        writeByte(0x3, false);
-        wait(0.00164);  // this command takes 1.64ms, so wait for it
+        writeByte(0x03, false);
+        wait(0.005);  // this command takes 1.64ms, so wait for it
     }
     writeByte(0x2, false);     // 4-bit mode
-    wait(0.000040f);    // most instructions take 40us
+    wait(0.000080f);    // most instructions take 40us
 
     writeCommand(0x28); // Function set 001 BW N F - -
+    wait(0.000080f);
     writeCommand(0x0C);
+    wait(0.000080f);
     writeCommand(0x6);  // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+    wait(0.000080f);
     cls();
 }
 
@@ -120,15 +123,17 @@
 }
 
 void TextLCD::writeNibble(int data, bool rs) {
+    data=data<<4;
+    data=data | 0x08; //backlight on
     if (rs) {
         data = data | RS_ON; // set rs bit
     }
     data |= E_ON; // E on
     writeI2CByte(data);
     data ^= E_ON; // E off
-    wait_us(1);
+    wait_us(100);
     writeI2CByte(data);
-    wait_us(1000);
+    wait_us(100);
 }
 
 void TextLCD::writeByte(int data, bool rs) {
diff -r 6beb6f498640 -r 3561ca8c9754 TextLCD.h
--- a/TextLCD.h	Mon Aug 09 14:17:02 2010 +0000
+++ b/TextLCD.h	Fri Apr 06 09:33:48 2018 +0000
@@ -25,8 +25,8 @@
 
 #include "mbed.h"
 
-#define E_ON 0x10
-#define RS_ON 0x80
+#define E_ON 0x04
+#define RS_ON 0x01
 
 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
  *
diff -r 6beb6f498640 -r 3561ca8c9754 main.cpp
--- a/main.cpp	Mon Aug 09 14:17:02 2010 +0000
+++ b/main.cpp	Fri Apr 06 09:33:48 2018 +0000
@@ -1,8 +1,15 @@
 #include "mbed.h"
 #include "TextLCD.h"
 
-TextLCD lcd(p9, p10);
-
+TextLCD lcd(PB_9, PB_8,0x4E);
+int k=0;
 int main() {
+    wait(1);
     lcd.printf("Hi mbed World!\n");
+    while(1)
+    {
+        wait(1);
+        lcd.printf("Hi mbed World %d!\n",k);
+        k++;
+    }
 }
diff -r 6beb6f498640 -r 3561ca8c9754 mbed.bld
--- a/mbed.bld	Mon Aug 09 14:17:02 2010 +0000
+++ b/mbed.bld	Fri Apr 06 09:33:48 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
+https://os.mbed.com/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file