F Malpartida avatar F Malpartida committed d706124

Removed un-necessary constructor methods: removed all those that contain lines and dots variables, since they are not used during initialization. These are initialized in the begin method.

Added some comments by Ragnar - original author of the library - to clarify ASIC connectivity.

Comments (0)

Files changed (5)

 
 void LCD::setCursor(uint8_t col, uint8_t row)
 {
-   int row_offsetsDef[]   = { 0x00, 0x40, 0x14, 0x54 }; // For regular LCDs
-   int row_offsetsLarge[] = { 0x00, 0x40, 0x10, 0x50 }; // For 16x4 LCDs
+   const byte row_offsetsDef[]   = { 0x00, 0x40, 0x14, 0x54 }; // For regular LCDs
+   const byte row_offsetsLarge[] = { 0x00, 0x40, 0x10, 0x50 }; // For 16x4 LCDs
    
    if ( row >= _numlines ) 
    {
 #define FAST_MODE
 
 /*!
+ @function
+ @abstract   waits for a given time in microseconds (compilation dependent).
+ @discussion Waits for a given time defined in microseconds depending on
+ the FAST_MODE define. If the FAST_MODE is defined the call will return
+ inmediatelly.
+ @param      uSec[in] time in microseconds.
+ @result     None
+ */
+inline static void waitUsec ( uint16_t uSec )
+{
+#ifndef FAST_MODE
+   delayMicroseconds ( uSec );
+#endif // FAST_MODE
+}
+
+
+/*!
  @defined 
  @abstract   All these definitions shouldn't be used unless you are writing 
  a driver.

LiquidCrystal.cpp

 #endif
 #include <LiquidCrystal.h>
 
-// STATIC helper routines
+// STATIC helper functions
 // ---------------------------------------------------------------------------
-/*!
-    @function
-    @abstract   waits for a given time in microseconds (compilation dependent).
-    @discussion Waits for a given time defined in microseconds depending on
-    the FAST_MODE define. If the FAST_MODE is defined the call will return
-    inmediatelly.
-    @param      uSec[in] time in microseconds.
-    @result     None
-*/
-inline static void waitUsec ( uint16_t uSec )
-{
-#ifndef FAST_MODE
-   delayMicroseconds ( uSec );
-#endif // FAST_MODE
-}
+
 
 // CONSTRUCTORS
 // ---------------------------------------------------------------------------

LiquidCrystal_SR.cpp

 // to the original functionality of the Arduino LiquidCrystal library and can
 // be used as such.
 //
-// Modified to work serially with the shiftOut() function, an 8-bit shiftregister 
-// (SR) and an LCD in 4-bit mode.
+// Modified to work serially with the shiftOut() function, an 8-bit
+// unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
+// shift register (IE a very simple SR), and an LCD in 4-bit mode.
+// Any such shift register should do (pref. 74LS family IC's for 2-wire).
+// I used 74LS164, for the reason that's what I had at hand.
 //
-// Shiftregister connection description (NEW as of 2009.07.27)
+// Connection description:
 //
-// Bit  #0 - N/C - not connected, used to hold a zero
-// Bits #1 - N/C
-// Bit  #2 - connects to RS (Register Select) on the LCD
-// Bits #3 - #6 from SR connects to LCD data inputs D4 - D7.
-// Bit  #7 - is used to enabling the enable-puls (via a diode-resistor AND "gate")
+// SR output:
+// Bit  #0   - N/C - not connected, used to hold a zero
+// Bit  #1   - N/C
+// Bit  #2   - connects to RS (Register Select) on the LCD
+// Bits #3-6 - connects to LCD data inputs D4 - D7.
+// Bit  #7   - enables the LCD enable-puls (via the diode-resistor AND "gate")
 //
-// 2 or 3 Pins required from the Arduino for Data, Clock, and Enable (optional). 
-// If not using Enable, the Data pin is used for the enable signal by defining 
-// the same pin for Enable as for Data. Data and Clock outputs/pins goes to the 
-// shiftregister.
-// LCD RW-pin hardwired to LOW (only writing to LCD). Busy Flag (BF, data bit D7) 
-// is not read.
-//
-// Any shift register should do. I used 74LS164, for the reason that's what I 
-// had at hand.
+// 2 or 3 Pins required from the Arduino for Data, Clock and (optional) Enable
+// If not using Enable, the Data pin is used for the enable signal by defining
+// the same pin for Enable as for Data. Data and Clock outputs/pins goes to
+// the shiftregister.
+// LCD RW-pin hardwired to LOW (only writing to LCD).
+// Busy Flag (BF, data bit D7) is not read.
 //
 //  Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
 //
+//
 // History
 // 2011.10.29  fmalpartida - adaption of the library to the LCD class hierarchy.
-// 2009.05.23  raron - but; based mostly (as in almost verbatim) on the 
-//             "official" LiquidCrystal library.
-// 2009.07.23  Incorporated some proper initialization routines
-//             inspired (lets say copy-paste-tweaked) from LiquidCrystal library 
-//             improvements from LadyAda
+// 2011.07.02  Fixed a minor flaw in setCursor function. No functional change, 
+//             just a bit more memory efficient.
+//             Thanks to CapnBry (from google code and github) who noticed it.
+//             URL to his version of shiftregLCD:
+//             https://github.com/CapnBry/HeaterMeter/commit/c6beba1b46b092ab0b33bcbd0a30a201fd1f28c1
+// 2009.07.30  raron - minor corrections to the comments.
+//             Fixed timing to datasheet safe. Fixed keyword highlights.
+// 2009.07.28  Mircho / raron - a new modification to the schematics, and a
+//             more streamlined interface
+// 2009.07.27  Thanks to an excellent suggestion from mircho at the Arduiono 
+//             playgrond forum, the number of wires now required is only two!
 // 2009.07.25  raron - Fixed comments. I really messed up the comments before 
 //             posting this, so I had to fix it.
-//             Also renamed a function, but no improvements or functional changes.
-// 2009.07.27  Thanks to an excellent suggestion from mircho at the Arduiono 
-//             playgrond forum, the number of wires now required is only two!
-// 2009.07.28  Mircho / raron - a new modification to the schematics, and a more 
-//             streamlined interface
-// 2009.07.30  raron - minor corrections to the comments. Fixed keyword highlights. 
-//             Fixed timing to datasheet safe.
-// 2011.07.02  Fixed a minor flaw in setCursor function. No functional change, 
-//             just a bit more memory efficient.
-//             Thanks to CapnBry (from google code and github) who noticed it. 
-//             URL to his version of shiftregLCD:
-//https://github.com/CapnBry/HeaterMeter/commit/c6beba1b46b092ab0b33bcbd0a30a201fd1f28c1
+//             Renamed a function, but no improvements or functional changes.
+// 2009.07.23  Incorporated some proper initialization routines
+//             inspired (lets say copy-paste-tweaked) from LiquidCrystal
+//             library improvements from LadyAda.
+// 2009.05.23  raron - first version, but based mostly (as in almost verbatim)
+//             on the "official" LiquidCrystal library.
 //
 //
 // This library is only compatible with Arduino's SDK version 1.0
 // LiquidCrystal constructor is called).
 // A call to begin() will reinitialize the LCD.
 
-// STATIC helper routines
+// STATIC helper functions
 // ---------------------------------------------------------------------------
-/*!
- @function
- @abstract   waits for a given time in microseconds (compilation dependent).
- @discussion Waits for a given time defined in microseconds depending on
- the FAST_MODE define. If the FAST_MODE is defined the call will return
- inmediatelly.
- @param      uSec[in] time in microseconds.
- @result     None
- */
-inline static void waitUsec ( uint16_t uSec )
-{
-#ifndef FAST_MODE
-   delayMicroseconds ( uSec );
-#endif // FAST_MODE
-}
 
 
 // CONSTRUCTORS
 {
 	init ( srdata, srclock, enable, 1, 0 );
 }
-// Set nr. of lines, assume 8 pixel high font
-LiquidCrystal_SR::LiquidCrystal_SR ( uint8_t srdata, uint8_t srclock, 
-                                     uint8_t enable, uint8_t lines ) 
-{
-	init ( srdata, srclock, enable, lines, 0 );
-}
 
-// Set nr. of lines and font
-LiquidCrystal_SR::LiquidCrystal_SR ( uint8_t srdata, uint8_t srclock, 
-                                     uint8_t enable, uint8_t lines, 
-                                     uint8_t font ) 
-{
-	init ( srdata, srclock, enable, lines, font );
-}
 
 
 // PRIVATE METHODS
    }
    digitalWrite( _enable_pin, LOW );
    
+   // Divide byte in two nibbles (val1 and val2), 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.
    val1 = mode | SR_EN_BIT | ((value >> 1) & 0x78); // upper nibble
    val2 = mode | SR_EN_BIT | ((value << 3) & 0x78); // lower nibble
    
    shiftOut ( _srdata_pin, _srclock_pin, MSBFIRST, val1 );
    
+   // LCD ENABLE PULSE
+   //
+   // While this library is written with a shift register without an output
+   // latch in mind, it can work in 3-wire mode with a shiftregister with a
+   // latch. The shiftregister latch pin (STR, RCL or similar) is then
+   // connected to the LCD enable pin. The LCD is (very likely) slower
+   // to read the Enable pulse, and then reads the new contents of the SR.
    digitalWrite( _enable_pin, HIGH );
    waitUsec( 1 );                 // enable pulse must be >450ns
    digitalWrite( _enable_pin, LOW );
    }
    shiftOut ( _srdata_pin, _srclock_pin, MSBFIRST, val2 );
    
+   // LCD ENABLE PULSE, se above comment
    digitalWrite( _enable_pin, HIGH );
    waitUsec( 1 );                 // enable pulse must be >450ns
    digitalWrite( _enable_pin, LOW );
       shiftOut ( _srdata_pin, _srclock_pin, MSBFIRST, 0x00 ); 
    }
    digitalWrite( _enable_pin, LOW );
-   
+
+   // Discard lower nibble
+   // and format it for shiftregister output wiring to the LCD
    val1 = SR_EN_BIT | ((value >> 1) & 0x78);
    shiftOut ( _srdata_pin, _srclock_pin, MSBFIRST, val1 );
-   
+
+   // LCD ENABLE PULSE
+   //
+   // While this library is written with a shift register without an output
+   // latch in mind, it can work in 3-wire mode with a shiftregister with a
+   // latch. The shiftregister latch pin (STR, RCL or similar) is then
+   // connected to the LCD enable pin. The LCD is (very likely) slower
+   // to read the Enable pulse, and then reads the new contents of the SR.
    digitalWrite( _enable_pin, HIGH );
    waitUsec( 1 );                 // enable pulse must be >450ns
    digitalWrite( _enable_pin, LOW );

LiquidCrystal_SR.h

 // to the original functionality of the Arduino LiquidCrystal library and can
 // be used as such.
 //
-// Modified to work serially with the shiftOut() function, an 8-bit shiftregister 
-// (SR) and an LCD in 4-bit mode.
+// Modified to work serially with the shiftOut() function, an 8-bit
+// unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
+// shift register (IE a very simple SR), and an LCD in 4-bit mode.
+// Any such shift register should do (pref. 74LS family IC's for 2-wire).
+// I used 74LS164, for the reason that's what I had at hand.
 //
-// Shiftregister connection description (NEW as of 2009.07.27)
+// Connection description:
 //
-// Bit  #0 - N/C - not connected, used to hold a zero
-// Bits #1 - N/C
-// Bit  #2 - connects to RS (Register Select) on the LCD
-// Bits #3 - #6 from SR connects to LCD data inputs D4 - D7.
-// Bit  #7 - is used to enabling the enable-puls (via a diode-resistor AND "gate")
+// SR output:
+// Bit  #0   - N/C - not connected, used to hold a zero
+// Bit  #1   - N/C
+// Bit  #2   - connects to RS (Register Select) on the LCD
+// Bits #3-6 - connects to LCD data inputs D4 - D7.
+// Bit  #7   - enables the LCD enable-puls (via the diode-resistor AND "gate")
 //
-// 2 or 3 Pins required from the Arduino for Data, Clock, and Enable (optional). 
-// If not using Enable, the Data pin is used for the enable signal by defining 
-// the same pin for Enable as for Data. Data and Clock outputs/pins goes to the 
-// shiftregister.
-// LCD RW-pin hardwired to LOW (only writing to LCD). Busy Flag (BF, data bit D7) 
-// is not read.
-//
-// Any shift register should do. I used 74LS164, for the reason that's what I 
-// had at hand.
+// 2 or 3 Pins required from the Arduino for Data, Clock and (optional) Enable
+// If not using Enable, the Data pin is used for the enable signal by defining
+// the same pin for Enable as for Data. Data and Clock outputs/pins goes to
+// the shiftregister.
+// LCD RW-pin hardwired to LOW (only writing to LCD).
+// Busy Flag (BF, data bit D7) is not read.
 //
 //  Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
 //
+//
 // History
 // 2011.10.29  fmalpartida - adaption of the library to the LCD class hierarchy.
-// 2009.05.23  raron - but; based mostly (as in almost verbatim) on the 
-//             "official" LiquidCrystal library.
-// 2009.07.23  Incorporated some proper initialization routines
-//             inspired (lets say copy-paste-tweaked) from LiquidCrystal library 
-//             improvements from LadyAda
+// 2011.07.02  Fixed a minor flaw in setCursor function. No functional change, 
+//             just a bit more memory efficient.
+//             Thanks to CapnBry (from google code and github) who noticed it.
+//             URL to his version of shiftregLCD:
+//             https://github.com/CapnBry/HeaterMeter/commit/c6beba1b46b092ab0b33bcbd0a30a201fd1f28c1
+// 2009.07.30  raron - minor corrections to the comments.
+//             Fixed timing to datasheet safe. Fixed keyword highlights.
+// 2009.07.28  Mircho / raron - a new modification to the schematics, and a
+//             more streamlined interface
+// 2009.07.27  Thanks to an excellent suggestion from mircho at the Arduiono 
+//             playgrond forum, the number of wires now required is only two!
 // 2009.07.25  raron - Fixed comments. I really messed up the comments before 
 //             posting this, so I had to fix it.
-//             Also renamed a function, but no improvements or functional changes.
-// 2009.07.27  Thanks to an excellent suggestion from mircho at the Arduiono 
-//             playgrond forum, the number of wires now required is only two!
-// 2009.07.28  Mircho / raron - a new modification to the schematics, and a more 
-//             streamlined interface
-// 2009.07.30  raron - minor corrections to the comments. Fixed keyword highlights. 
-//             Fixed timing to datasheet safe.
-// 2011.07.02  Fixed a minor flaw in setCursor function. No functional change, 
-//             just a bit more memory efficient.
-//             Thanks to CapnBry (from google code and github) who noticed it. 
-//             URL to his version of shiftregLCD:
-//https://github.com/CapnBry/HeaterMeter/commit/c6beba1b46b092ab0b33bcbd0a30a201fd1f28c1
+//             Renamed a function, but no improvements or functional changes.
+// 2009.07.23  Incorporated some proper initialization routines
+//             inspired (lets say copy-paste-tweaked) from LiquidCrystal
+//             library improvements from LadyAda.
+// 2009.05.23  raron - first version, but based mostly (as in almost verbatim)
+//             on the "official" LiquidCrystal library.
 //
 //
 // This library is only compatible with Arduino's SDK version 1.0
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.