F Malpartida avatar F Malpartida committed fa28f92

Begin method has been implemented in the top parent LCD class. The different ports now only have to provide methods to initialize the device driving the LCD, provide methods for the specifics to write to the LCD device.

The begin method can be overloaded if necessary to initialize any HW that is implemented by a library and can't be done during construction.

Comments (0)

Files changed (10)

 
 // PUBLIC METHODS
 // ---------------------------------------------------------------------------
+// When the display powers up, it is configured as follows:
+//
+// 1. Display clear
+// 2. Function set: 
+//    DL = 1; 8-bit interface data 
+//    N = 0; 1-line display 
+//    F = 0; 5x8 dot character font 
+// 3. Display on/off control: 
+//    D = 0; Display off 
+//    C = 0; Cursor off 
+//    B = 0; Blinking off 
+// 4. Entry mode set: 
+//    I/D = 1; Increment by 1 
+//    S = 0; No shift 
+//
+// Note, however, that resetting the Arduino doesn't reset the LCD, so we
+// can't assume that its in that state when a sketch starts (and the
+// LiquidCrystal constructor is called).
+// A call to begin() will reinitialize the LCD.
+//
+void LCD::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) 
+{
+   if (lines > 1) 
+   {
+      _displayfunction |= LCD_2LINE;
+   }
+   _numlines = lines;
+   _cols = cols;
+   
+   // for some 1 line displays you can select a 10 pixel high font
+   // ------------------------------------------------------------
+   if ((dotsize != 0) && (lines == 1)) 
+   {
+      _displayfunction |= LCD_5x10DOTS;
+   }
+   
+   // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
+   // according to datasheet, we need at least 40ms after power rises above 2.7V
+   // before sending commands. Arduino can turn on way before 4.5V so we'll wait 
+   // 50
+   // ---------------------------------------------------------------------------
+   delayMicroseconds(50000); 
+      
+   //put the LCD into 4 bit or 8 bit mode
+   // -------------------------------------
+   if (! (_displayfunction & LCD_8BITMODE)) 
+   {
+      // this is according to the hitachi HD44780 datasheet
+      // figure 24, pg 46
+      
+      // we start in 8bit mode, try to set 4 bit mode
+      command ( 0x03 );
+      delayMicroseconds(4500); // wait min 4.1ms
+      
+      // second try
+      command ( 0x03 );
+      delayMicroseconds(4500); // wait min 4.1ms
+      
+      // third go!
+      command ( 0x03 ); 
+      delayMicroseconds(150);
+      
+      // finally, set to 4-bit interface
+      command ( 0x02 ); 
+   } 
+   else 
+   {
+      // this is according to the hitachi HD44780 datasheet
+      // page 45 figure 23
+      
+      // Send function set command sequence
+      command(LCD_FUNCTIONSET | _displayfunction);
+      delayMicroseconds(4500);  // wait more than 4.1ms
+      
+      // second try
+      command(LCD_FUNCTIONSET | _displayfunction);
+      delayMicroseconds(150);
+      
+      // third go
+      command(LCD_FUNCTIONSET | _displayfunction);
+   }
+   
+   // finally, set # lines, font size, etc.
+   command(LCD_FUNCTIONSET | _displayfunction);  
+   
+   // turn the display on with no cursor or blinking default
+   _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
+   display();
+   
+   // clear the LCD
+   clear();
+   
+   // Initialize to default text direction (for romance languages)
+   _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
+   // set the entry mode
+   command(LCD_ENTRYMODESET | _displaymode);
+   
+}
 
 // Common LCD Commands
 // ---------------------------------------------------------------------------
     @param      cols[in] the number of columns that the display has
     @param      rows[in] the number of rows that the display has
     */
-#if (ARDUINO <  100)
-   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) { };
-#else
-   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) = 0;
-#endif
-   
+   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
+  
    /*!
     @function
     @abstract   Clears the LCD.

LiquidCrystal.cpp

 // PRIVATE METHODS
 // ---------------------------------------------------------------------------
 
-// When the display powers up, it is configured as follows:
-//
-// 1. Display clear
-// 2. Function set: 
-//    DL = 1; 8-bit interface data 
-//    N = 0; 1-line display 
-//    F = 0; 5x8 dot character font 
-// 3. Display on/off control: 
-//    D = 0; Display off 
-//    C = 0; Cursor off 
-//    B = 0; Blinking off 
-// 4. Entry mode set: 
-//    I/D = 1; Increment by 1 
-//    S = 0; No shift 
-//
-// Note, however, that resetting the Arduino doesn't reset the LCD, so we
-// can't assume that its in that state when a sketch starts (and the
-// LiquidCrystal constructor is called).
-// A call to begin() will reinitialize the LCD.
-//
+
 // init
 void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
                          uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
       _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
    else 
       _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
-}
-
-// PUBLIC METHODS
-// ---------------------------------------------------------------------------
-
-//
-// begin
-void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) 
-{
-   if (lines > 1) 
-   {
-      _displayfunction |= LCD_2LINE;
-   }
-   _numlines = lines;
-   _cols = cols;
-   
-   // for some 1 line displays you can select a 10 pixel high font
-   // ------------------------------------------------------------
-   if ((dotsize != 0) && (lines == 1)) 
-   {
-      _displayfunction |= LCD_5x10DOTS;
-   }
-   
-   // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
-   // according to datasheet, we need at least 40ms after power rises above 2.7V
-   // before sending commands. Arduino can turn on way before 4.5V so we'll wait 
-   // 50
-   // ---------------------------------------------------------------------------
-   delayMicroseconds(50000); 
    
    // Now we pull both RS and R/W low to begin commands
    digitalWrite(_rs_pin, LOW);
    { 
       digitalWrite(_rw_pin, LOW);
    }
-   
-   //put the LCD into 4 bit or 8 bit mode
-   // -------------------------------------
-   if (! (_displayfunction & LCD_8BITMODE)) 
-   {
-      // this is according to the hitachi HD44780 datasheet
-      // figure 24, pg 46
-      
-      // we start in 8bit mode, try to set 4 bit mode
-      writeNbits(0x03, 4);
-      delayMicroseconds(4500); // wait min 4.1ms
-      
-      // second try
-      writeNbits(0x03, 4);
-      delayMicroseconds(4500); // wait min 4.1ms
-      
-      // third go!
-      writeNbits(0x03, 4); 
-      delayMicroseconds(150);
-      
-      // finally, set to 4-bit interface
-      writeNbits(0x02, 4); 
-   } 
-   else 
-   {
-      // this is according to the hitachi HD44780 datasheet
-      // page 45 figure 23
-      
-      // Send function set command sequence
-      command(LCD_FUNCTIONSET | _displayfunction);
-      delayMicroseconds(4500);  // wait more than 4.1ms
-      
-      // second try
-      command(LCD_FUNCTIONSET | _displayfunction);
-      delayMicroseconds(150);
-      
-      // third go
-      command(LCD_FUNCTIONSET | _displayfunction);
-   }
-   
-   // finally, set # lines, font size, etc.
-   command(LCD_FUNCTIONSET | _displayfunction);  
-   
-   // turn the display on with no cursor or blinking default
-   _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
-   display();
-   
-   // clear the LCD
-   clear();
-   
-   // Initialize to default text direction (for romance languages)
-   _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-   // set the entry mode
-   command(LCD_ENTRYMODESET | _displaymode);
-   
 }
 
+// PUBLIC METHODS
+// ---------------------------------------------------------------------------
+
 /************ low level data pushing commands **********/
 
 // send
    
    /*!
     @function
-    @abstract   LCD initialization.
-    @discussion Initializes the LCD to a given size (col, row). This methods
-    initializes the LCD, therefore, it MUST be called prior to using any other
-    method from this class or parent class.
-    
-    @param      cols[in] the number of columns that the display has
-    @param      rows[in] the number of rows that the display has
-    @param      charsize: size of the characters of the LCD: LCD_5x8DOTS or
-    LCD_5x10DOTS.
-    */
-   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);   
-   
-   /*!
-    @function
     @abstract   Send a particular value to the LCD.
     @discussion Sends a particular value to the LCD for writing to the LCD or
     as an LCD command.
    
    /*!
     @method     
-    @abstract   Initializes the LCD pin allocation
+    @abstract   Initializes the LCD pin allocation and associated HW
     @discussion Initializes the LCD pin allocation and configuration.
     */
    void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,

LiquidCrystal_I2C.cpp

 {
    
    init();     // Initialise the I2C expander interface
-   
-   if (lines > 1) 
-   {
-      _displayfunction |= LCD_2LINE;
-   }
-   _numlines = lines;
-   _cols = cols;
-   
-   // for some 1 line displays you can select a 10 pixel high font
-   if ((dotsize != 0) && (lines == 1)) {
-      _displayfunction |= LCD_5x10DOTS;
-   }
-   
-   // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
-   // according to datasheet, we need at least 40ms after power rises above 2.7V
-   // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50
-   delayMicroseconds(50000); 
-   
-   // Now we pull both RS and R/W low to begin commands
-   expanderWrite ( _backlightval );   // reset expander and turn backlight off (Bit 8 =1)
-   delay(1000);
-   
-   //put the LCD into 4 bit mode
-   // this is according to the hitachi HD44780 datasheet
-   // figure 24, pg 46
-   
-   // we start in 8bit mode, try to set 4 bit mode
-   write4bits ( 0x03, LOW );
-   delayMicroseconds(4500); // wait min 4.1ms
-   
-   // second try
-   write4bits ( 0x03, LOW );
-   delayMicroseconds(4500); // wait min 4.1ms
-   
-   // third go!
-   write4bits ( 0x03, LOW ); 
-   delayMicroseconds(150);
-   
-   // finally, set to 4-bit interface
-   write4bits ( 0x02, LOW ); 
-   
-   
-   // set # lines, font size, etc.
-   command(LCD_FUNCTIONSET | _displayfunction);  
-   
-   // turn the display on with no cursor or blinking default
-   _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
-   display();
-   
-   // clear it off
-   clear();
-   
-   // Initialize to default text direction (for roman languages)
-   _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-   
-   // set the entry mode
-   command(LCD_ENTRYMODESET | _displaymode);
-   
-   home();
-   
+   LCD::begin ( cols, lines, dotsize );   
 }
 
 

LiquidCrystal_I2C.h

    
    /*!
     @function
-    @abstract   LCD initialization.
+    @abstract   LCD initialization and associated HW.
     @discussion Initializes the LCD to a given size (col, row). This methods
     initializes the LCD, therefore, it MUST be called prior to using any other
     method from this class or parent class.
     
+    The begin method can be overloaded if necessary to initialize any HW that 
+    is implemented by a library and can't be done during construction, here
+    we use the Wire class.
+    
     @param      cols[in] the number of columns that the display has
     @param      rows[in] the number of rows that the display has
     @param      charsize[in] size of the characters of the LCD: LCD_5x8DOTS or

LiquidCrystal_SR.cpp

 
 #include <FastIO.h>
 
-// When the display powers up, it is configured as follows:
-//
-// 1. Display clear
-// 2. Function set: 
-//    DL = 1; 8-bit interface data 
-//    N = 0; 1-line display 
-//    F = 0; 5x8 dot character font 
-// 3. Display on/off control: 
-//    D = 0; Display off 
-//    C = 0; Cursor off 
-//    B = 0; Blinking off 
-// 4. Entry mode set: 
-//    I/D = 1; Increment by 1 
-//    S = 0; No shift 
-//
-// Note, however, that resetting the Arduino doesn't reset the LCD, so we
-// can't assume that its in that state when a sketch starts (and the
-// LiquidCrystal constructor is called).
-// A call to begin() will reinitialize the LCD.
-
-// STATIC helper functions
-// ---------------------------------------------------------------------------
-
 
 // CONSTRUCTORS
 // ---------------------------------------------------------------------------
 }
 
 
-
 // PRIVATE METHODS
 // ---------------------------------------------------------------------------
 
    _srClockRegister = fio_pinToOutputRegister(srclock);
    _srClockBit = fio_pinToBit(srclock);
 
-   if (enable == TWO_WIRE){
+   if (enable == TWO_WIRE)
+   {
       _two_wire   = 1;
       _srEnableRegister = _srDataRegister;
       _srEnableBit = _srDataBit;
-   }else{
+   }
+   else
+   {
       _srEnableRegister = fio_pinToOutputRegister(enable);
       _srEnableBit = fio_pinToBit(enable);
    }
 // PUBLIC METHODS
 // ---------------------------------------------------------------------------
 
-//
-// begin
-void LiquidCrystal_SR::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) 
-{
-   
-   if (lines > 1) 
-   {
-      _displayfunction |= LCD_2LINE;
-   }
-
-   _numlines = lines;
-   _cols = cols;
-   
-   // for some 1 line displays you can select a 10 pixel high font
-   // ------------------------------------------------------------
-   if ((dotsize != 0) && (lines == 1)) 
-   {
-      _displayfunction |= LCD_5x10DOTS;
-   }
-   
-   // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
-   // according to datasheet, we need at least 40ms after power rises above 2.7V
-   // before sending commands. Arduino can turn on way before 4.5V so we'll wait 
-   // 50
-   // ---------------------------------------------------------------------------
-   delayMicroseconds(50000);
-   write4bits(LCD_FUNCTIONSET | LCD_8BITMODE);
-   delayMicroseconds(4500);  // wait more than 4.1ms
-   
-   // Second try
-   write4bits(LCD_FUNCTIONSET | LCD_8BITMODE);
-   delayMicroseconds(150);
-   // Third go
-   write4bits(LCD_FUNCTIONSET | LCD_8BITMODE);
-   
-   // And finally, set to 4-bit interface
-   write4bits(LCD_FUNCTIONSET | LCD_4BITMODE);
-   
-   // Set # lines, font size, etc.
-   command(LCD_FUNCTIONSET | _displayfunction);
-   // Turn the display on with no cursor or blinking default
-   _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
-   display();
-   // Clear it off
-   clear();
-   // Initialize to default text direction (for romance languages)
-   _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-   // set the entry mode
-   command(LCD_ENTRYMODESET | _displaymode);
-   home();
-   
-}
 
 /************ low level data pushing commands **********/
 

LiquidCrystal_SR.h

    
    /*!
     @function
-    @abstract   LCD initialization.
-    @discussion Initializes the LCD to a given size (col, row). This methods
-    initializes the LCD, therefore, it MUST be called prior to using any other
-    method from this class or parent class.
-    
-    @param      cols[in] the number of columns that the display has
-    @param      rows[in] the number of rows that the display has
-    @param      charsize[in] size of the characters of the LCD: LCD_5x8DOTS or
-    LCD_5x10DOTS.
-    */
-   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);   
-   
-   /*!
-    @function
     @abstract   Send a particular value to the LCD.
     @discussion Sends a particular value to the LCD for writing to the LCD or
     as an LCD command using the shift register.

LiquidCrystal_SR_LCD3.cpp

 // PUBLIC METHODS
 // ---------------------------------------------------------------------------
 
-//
-// begin
-void LiquidCrystal_SR_LCD3::begin( uint8_t cols, uint8_t lines, uint8_t dotsize ) 
-{
-   if (lines > 1) 
-   {
-      _displayfunction |= LCD_2LINE;
-   }
-   
-   _numlines = lines;
-   _cols = cols;
-   
-   // for some 1 line displays you can select a 10 pixel high font
-   // ------------------------------------------------------------
-   if ((dotsize != 0) && (lines == 1)) 
-   {
-      _displayfunction |= LCD_5x10DOTS;
-   }
-   
-   // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
-   // according to datasheet, we need at least 40ms after power rises above 2.7V
-   // before sending commands. Arduino can turn on way before 4.5V so we'll wait 
-   // 50
-   // ---------------------------------------------------------------------------
-   delayMicroseconds(50000);
-   
-   // This init is copied verbatim from the spec sheet.
-   // 8 bit codes are shifted to 4 bit
-   write4bits((LCD_FUNCTIONSET | LCD_8BITMODE) >> 4);
-   delayMicroseconds(4500);  // wait more than 4.1ms
-   
-   // Second try
-   write4bits((LCD_FUNCTIONSET | LCD_8BITMODE) >> 4);
-   delayMicroseconds(150);
-   // Third go
-   write4bits((LCD_FUNCTIONSET | LCD_8BITMODE) >> 4);
-   
-   // And finally, set to 4-bit interface
-   write4bits((LCD_FUNCTIONSET | LCD_4BITMODE) >> 4);
-   
-   // Set # lines, font size, etc.
-   command(LCD_FUNCTIONSET | _displayfunction);
-   // Turn the display on with no cursor or blinking default
-   _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
-   display();
-   // Clear it off
-   clear();
-   // Initialize to default text direction (for romance languages)
-   _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
-   // set the entry mode
-   command(LCD_ENTRYMODESET | _displaymode);
-   home();
-   
-}
 
 /************ low level data pushing commands **********/
 

LiquidCrystal_SR_LCD3.h

     */
    LiquidCrystal_SR_LCD3 ( uint8_t srdata, uint8_t srclock, uint8_t enable );
    
-   
-   /*!
-    @function
-    @abstract   LCD initialization.
-    @discussion Initializes the LCD to a given size (col, row). This methods
-    initializes the LCD, therefore, it MUST be called prior to using any other
-    method from this class or parent class.
-    
-    @param      cols[in] the number of columns that the display has
-    @param      rows[in] the number of rows that the display has
-    @param      charsize[in] size of the characters of the LCD: LCD_5x8DOTS or
-    LCD_5x10DOTS.
-    */
-   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);   
-   
    /*!
     @function
     @abstract   Send a particular value to the LCD.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.