Commits

F Malpartida committed 0583311

Modified the send method to initialize correctly the LCD. Send method now has three modes: COMMAND, DATA, FOUR_BITS.
setBacklight method check if a particular pin is mapped to a PMW.

  • Participants
  • Parent commits 762521a

Comments (0)

Files changed (7)

       // figure 24, pg 46
       
       // we start in 8bit mode, try to set 4 bit mode
-      command ( 0x03 );
+      send(0x03, FOUR_BITS);
       delayMicroseconds(4500); // wait min 4.1ms
       
       // second try
-      command ( 0x03 );
+      send ( 0x03, FOUR_BITS );
       delayMicroseconds(4500); // wait min 4.1ms
       
       // third go!
-      command ( 0x03 ); 
+      send( 0x03, FOUR_BITS );
       delayMicroseconds(150);
       
       // finally, set to 4-bit interface
-      command ( 0x02 ); 
+      send ( 0x02, FOUR_BITS ); 
    } 
    else 
    {
 // ---------------------------------------------------------------------------
 #define COMMAND                 0
 #define DATA                    1
+#define FOUR_BITS               2
 
 /*!
  @defined 

LiquidCrystal.cpp

 // ---------------------------------------------------------------------------
 
 /************ low level data pushing commands **********/
-
+//
 // send
 void LiquidCrystal::send(uint8_t value, uint8_t mode) 
 {
-   digitalWrite( _rs_pin, mode );
+   // Only interested in COMMAND or DATA
+   digitalWrite( _rs_pin, ( mode == DATA ) );
    
    // if there is a RW pin indicated, set it low to Write
    // ---------------------------------------------------
       digitalWrite(_rw_pin, LOW);
    }
    
-   if (_displayfunction & LCD_8BITMODE)
-   {
-      writeNbits(value, 8); 
+   if ( mode != FOUR_BITS )
+   {   
+      if ( (_displayfunction & LCD_8BITMODE ) )
+      {
+         writeNbits(value, 8); 
+      } 
+      else 
+      {
+         writeNbits ( value >> 4, 4 );
+         writeNbits ( value, 4 );
+      }
    } 
    else 
    {
-      writeNbits ( value >> 4, 4 );
       writeNbits ( value, 4 );
    }
    waitUsec ( EXEC_TIME ); // wait for the command to execute by the LCD
 {
    if ( _backlightPin != LCD_NOBACKLIGHT )
    {
-      analogWrite ( _backlightPin, value );
+      if(digitalPinToTimer(_backlightPin) != NOT_ON_TIMER)
+      {
+         analogWrite ( _backlightPin, value );
+      }
+      else if(value)
+      {
+         digitalWrite( _backlightPin, HIGH);
+      }
+      else
+      {
+         digitalWrite( _backlightPin, LOW);
+      }
    }
 }
 
     backlight, the configuration pin must be a PWM output pin. Dim control
     is achieved by passing a value from 1 to 255 as a parameter. If the
     pin configured when calling the setBacklightPin does not support PWM,
-    then: (0..127) backlight off, (128..255) backlight on.
+    then: (0) backlight off, (1..255) backlight on.
     
     @param      value: backlight value. 0: off, 1..255: dim control of the 
     backlight. For negative logic 255: off, 254..0: dim control.
-    For non PWM pins: 0..127 - backligh off, 128..255 - backlight on.
     */
    void setBacklight ( uint8_t value );
    

LiquidCrystal_I2C.cpp

    // No need to use the delay routines since the time taken to write takes
    // longer that what is needed both for toggling and enable pin an to execute
    // the command.
-   write4bits( (value >> 4), mode );
-   write4bits( (value & 0x0F), mode);
+   
+   if ( mode == FOUR_BITS )
+   {
+      write4bits( (value & 0x0F), COMMAND );
+   }
+   else 
+   {
+      write4bits( (value >> 4), mode );
+      write4bits( (value & 0x0F), mode);
+   }
 }
 
 //

LiquidCrystal_SR.cpp

 {
    // Divide byte in two nibbles include the RS signal
    // and format it for shiftregister output wiring to the LCD
-   mode = mode ? SR_RS_BIT : 0; // RS bit; LOW: command.  HIGH: character.
-   shiftIt(mode | SR_EN_BIT | ((value >> 1) & 0x78)); // upper nibble
-   shiftIt(mode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
+   // We are only interested in my COMMAND or DATA for myMode
+   uint8_t myMode = ( mode == DATA ) ? SR_RS_BIT : 0; // RS bit; LOW: command.  HIGH: character.
+   
+   if ( mode != FOUR_BITS )
+   {
+      shiftIt(myMode | SR_EN_BIT | ((value >> 1) & 0x78)); // upper nibble
+      shiftIt(myMode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
+
+   }
+   else 
+   {
+      shiftIt(myMode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
+   }
 }
 
 //

LiquidCrystal_SR_LCD3.cpp

 #define SR_RS_BIT B01000000   // LOW: command. HIGH: character.
 
 void LiquidCrystal_SR_LCD3::send(uint8_t value, uint8_t mode) 
-{
-   uint8_t nibble;
+{   
+   // only interested on COMMAND or DATA
+   uint8_t myMode = ( mode == DATA ) ? SR_RS_BIT : 0; // RS bit; LOW: command.  HIGH: character.
    
-   mode = mode ? SR_RS_BIT : 0; // RS bit; LOW: command.  HIGH: character.
-   
-   nibble = value >> 4; // Get high nibble.
-   write4bits(nibble | mode);
-   
-   //delay(1); // This was in the LCD3 code but does not seem needed -- merlin
-   
-   nibble = value & 15; // Get low nibble
-   write4bits(nibble | mode);
+   if ( mode != FOUR_BITS )
+   {
+      write4bits( ( value >> 4 ) | myMode);
+      write4bits( ( value & 0x0F ) | myMode);
+   }
+   else 
+   {
+      write4bits( ( value & 0x0F ) | myMode);
+   }
+
 }
 
 void LiquidCrystal_SR_LCD3::write4bits(uint8_t nibble)