Driver for a Text LCD using a PCF8574 over I2C

Dependencies:   mbed

Fork of I2CTextLCD by Romilly Cocking

Files at this revision

API Documentation at this revision

Comitter:
mijimy
Date:
Tue Jan 19 07:50:15 2016 +0000
Parent:
2:628a00fec43c
Commit message:
i2c pcf8574t lcd 20x4 .. remove crash after certain cycle

Changed in this revision

i2clcd/TextLCD.cpp 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
diff -r 628a00fec43c -r 846b36e1f4d5 i2clcd/TextLCD.cpp
--- a/i2clcd/TextLCD.cpp	Mon Jan 18 04:02:04 2016 +0000
+++ b/i2clcd/TextLCD.cpp	Tue Jan 19 07:50:15 2016 +0000
@@ -52,8 +52,9 @@
 #include "mbed.h"
 
 
-TextLCD::TextLCD(PinName sda, PinName scl, int i2cAddress, LCDType type) : _i2c(sda, scl), _type(type) {
-    _i2cAddress = i2cAddress;
+TextLCD::TextLCD(PinName sda, PinName scl, int i2cAddress, LCDType type) : _i2c(sda, scl), _i2cAddress(i2cAddress) , _type(type){
+   // _i2cAddress = i2cAddress;
+    writeByte(E_ON,false);
     wait(0.015);        // Wait 15ms to ensure powered up
 
     // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
@@ -114,7 +115,7 @@
 
 void TextLCD::writeI2CByte(int data) {
     // equivalent to writeI2CByte
-    char * cmd = new char[1];
+    char cmd[1];
     cmd[0] = data;
     _i2c.write(_i2cAddress, cmd, 1);
 }
@@ -128,9 +129,11 @@
     data |= E_ON; // E on
     writeI2CByte(data);
     data ^= E_ON; // E off
-    wait_us(1);
+    //wait_us(1);
+     wait(0.000001f); // most instructions take 40us
     writeI2CByte(data);
-    wait_us(1000);
+     wait(0.001f); // most instructions take 40us
+  //  wait_us(1000);
 }
 
 void TextLCD::writeByte(int data, bool rs) {
diff -r 628a00fec43c -r 846b36e1f4d5 main.cpp
--- a/main.cpp	Mon Jan 18 04:02:04 2016 +0000
+++ b/main.cpp	Tue Jan 19 07:50:15 2016 +0000
@@ -11,7 +11,7 @@
         lcd.locate(4,2);
         lcd.printf("count:");
         while(1)
-        {   for(count=0;count<21;count+=1)
+        {   for(count=0;count<100;count+=1)
             {   lcd.locate(11,2); 
                 lcd.printf(" %d ",count);
                 wait(0.5);