Commits

F Malpartida committed 76c3db7

Corrected minor bugs and fixed timings for enable toggle so that it is more in-line with slow LCDs.

Comments (0)

Files changed (4)

LiquidCrystal.cpp

       // figure 24, pg 46
       
       // we start in 8bit mode, try to set 4 bit mode
-      write4bits(0x03);
+      writeNbits(0x03, 4);
       delayMicroseconds(4500); // wait min 4.1ms
       
       // second try
-      write4bits(0x03);
+      writeNbits(0x03, 4);
       delayMicroseconds(4500); // wait min 4.1ms
       
       // third go!
-      write4bits(0x03); 
+      writeNbits(0x03, 4); 
       delayMicroseconds(150);
       
       // finally, set to 4-bit interface
-      write4bits(0x02); 
+      writeNbits(0x02, 4); 
    } 
    else 
    {
    
    if (_displayfunction & LCD_8BITMODE)
    {
-      write8bits(value); 
+      writeNbits(value, 8); 
    } 
    else 
    {
-      write4bits ( value >> 4 );
-      write4bits ( value );
+      writeNbits ( value >> 4, 4 );
+      writeNbits ( value, 4 );
    }
    waitUsec ( EXEC_TIME ); // wait for the command to execute by the LCD
 }
    digitalWrite(_enable_pin, HIGH);   
    waitUsec(1);          // enable pulse must be > 450ns   
    digitalWrite(_enable_pin, LOW);
+   waitUsec(20);
 }
 
 //
 // write4bits
-void LiquidCrystal::write4bits(uint8_t value) 
+void LiquidCrystal::writeNbits(uint8_t value, uint8_t numBits) 
 {
-   for (uint8_t i = 0; i < 4; i++) 
+   for (uint8_t i = 0; i < numBits; i++) 
    {
       digitalWrite(_data_pins[i], (value >> i) & 0x01);
    }
    pulseEnable();
 }
-
-//
-// write8bits
-void LiquidCrystal::write8bits(uint8_t value) 
-{
-   for (uint8_t i = 0; i < 8; i++) 
-   {
-      digitalWrite(_data_pins[i], (value >> i) & 0x01);
-   }   
-   pulseEnable();
-}
    
    /*!
     @method     
-    @abstract   Writes an 8 bit value to the LCD.
-    @discussion Writes 8 bits to the LCD control data lines.
-    */
-   void write8bits(uint8_t value);
-   
-   /*!
-    @method     
-    @abstract   Writes an 4 bit value to the LCD.
-    @discussion Writes 4 bits (the least significant) to the LCD control data lines.
+    @abstract   Writes numBits bits from value value to the LCD.
+    @discussion Writes numBists bits (the least significant) to the LCD control 
+    data lines.
     */   
-   void write4bits(uint8_t value);
+   void writeNbits(uint8_t value, uint8_t numBits);
    
    /*!
     @method     

LiquidCrystal_SR.h

     */
    LiquidCrystal_SR ( uint8_t srdata, uint8_t srclock, uint8_t enable );
    
-   
-   // Set nr. of lines, assume 8 pixel high font
-   LiquidCrystal_SR ( uint8_t srdata, uint8_t srclock, uint8_t enable, 
-                     uint8_t lines );
-   
-   // Set nr. of lines and font
-   LiquidCrystal_SR( uint8_t srdata, uint8_t srclock, uint8_t enable, 
-                    uint8_t lines, uint8_t font );
-   
-   
    /*!
     @function
     @abstract   LCD initialization.

examples/i2cLCDextraIO/i2cLCDextraIO.pde

    
    Serial.begin ( 57600 );
    analogReference ( INTERNAL );
-   pinMode ( LDR_PIN, INPUT );
    
 #ifdef _LCD_4BIT_
   pinMode(CONTRAST_PIN, OUTPUT);