Rod Coleman / I2CTextLCD
Revision:
2:24c878e63f10
Parent:
1:e60cbc407d73
Child:
3:4b9faffb3f98
--- a/I2CTextLCD.cpp	Thu Aug 18 13:05:56 2011 +0000
+++ b/I2CTextLCD.cpp	Tue Aug 23 11:29:30 2011 +0000
@@ -44,19 +44,12 @@
     _rows = rows;
     _backlight=backlight;
     //_i2c.frequency(70000);
-  
-
-    // Should theoretically wait 15ms, but most things will be powered up pre-reset
-    // so i'll disable that for the minute. If implemented, could wait 15ms post reset
-    // instead
-    // Winstar 20x4 WH2004-NYG- needs 40ms after VDD> 4,5V
+ // Winstar 20x4 WH2004-NYG- needs 40ms after VDD> 4,5V
      wait(0.05);
-
-    // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
-
-    for (int i=0; i<3; i++) {
+// send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+for (int i=0; i<3; i++) {
      writeCommand(0x3); //send 3 times mode
-        wait(0.00164);      // this command takes 1.64ms, so wait for it
+      wait(0.00164);      // this command takes 1.64ms, so wait for it
     }
     writeCommand(0x2); // 4-bit mode
     writeCommand(0x2); // 4-bit mode
@@ -117,7 +110,7 @@
     }
     _row = row;
     _column = column;
-    int address;
+    int address = 0x80;
     if (row==0){
     address = 0x80+_column;
     }
@@ -149,18 +142,17 @@
     cls();
 }
 
-void I2CTextLCD::writeByte(int c, bool rs) {
-   // void writeByte(char c, bool rs){
-      char cmd[2]; //led = 1;
+void I2CTextLCD::writeByte(int c, bool rs) {  // This is the actual I2C transfer of the display data:
+        char cmd[2]; //led = 1;
         cmd[0]=c>>2;                  // upper nibble
-        cmd[0]=cmd[0] & 0x3c;
+        cmd[0]=cmd[0] & 0x3c;         // mask out bits other than 5:2 for data (RS and E are enabled separately, below:)
         cmd[1]=c<<2;                 // lower nibble
         cmd[1]=cmd[1] & 0x3c;
         if (rs) {
-        cmd[0]=cmd[0] | 0x01;
+        cmd[0]=cmd[0] | 0x01;        // RS selects display DATA or a COMMAND. It's on bit 0:
         cmd[1]=cmd[1] | 0x01;
         }
-        _i2c.write( _i2cAddress,cmd,1); // E=0, write upper nibble
+        _i2c.write( _i2cAddress,cmd,1); // E=0, write upper nibble. E's on bit 1!
         wait_us(1);
         cmd[0]=cmd[0]|0x02; //E=1
         _i2c.write( _i2cAddress, cmd,1); 
@@ -179,6 +171,7 @@
         // led = 0;
         wait_us(1);
     }
+ // This is the original authors method:
     //void I2CTextLCD::writeByte(int data, bool rs) {