Commits

piccaso  committed 96ab5af

removed unused write4bits from SR
updated keywords
unified examples extension

  • Participants
  • Parent commits 64c971b
  • Branches V 1.2.0 preparation

Comments (0)

Files changed (12)

 //
 // @version API 1.0.0
 //
-// @author Florial Fida - 
+// @author Florian Fida -
 //
 // @todo:
 //  support chipkit:
 //
 // @version API 1.0.0
 //
-// @author Florial Fida - 
+// @author Florian Fida -
 //
 // @todo:
 //  support chipkit:

File LiquidCrystal_SR.cpp

 //
 //
 // History
-// 2012.01.16  flo - faster digitalWrite/shiftOut
+// 2012.01.16  Florian Fida - faster digitalWrite/shiftOut
 // 2011.10.29  fmalpartida - adaption of the library to the LCD class hierarchy.
 // 2011.07.02  Fixed a minor flaw in setCursor function. No functional change, 
 //             just a bit more memory efficient.
 #else
 #include <Arduino.h>
 #endif
-#include <LiquidCrystal_SR.h>
+#include "LiquidCrystal_SR.h"
 
 #include "FastIO.h"
 
 
 //
 // init
-void LiquidCrystal_SR::init( uint8_t srdata, uint8_t srclock, uint8_t enable, 
-                             uint8_t lines, uint8_t font )
+void LiquidCrystal_SR::init(uint8_t srdata, uint8_t srclock, uint8_t enable, uint8_t lines, uint8_t font)
 {
    // Initialise private variables
-   _two_wire    = 0;
+   _two_wire = 0;
 
    _srDataRegister = fio_pinToOutputRegister(srdata);
    _srDataBit = fio_pinToBit(srdata);
 
    if (enable == TWO_WIRE)
    {
-      _two_wire   = 1;
+      _two_wire = 1;
       _srEnableRegister = _srDataRegister;
       _srEnableBit = _srDataBit;
    }
    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x10DOTS;
 }
 
-// PUBLIC METHODS
-// ---------------------------------------------------------------------------
-
-
-/************ low level data pushing commands **********/
-
-// send
-void LiquidCrystal_SR::send(uint8_t value, uint8_t mode) 
+// shiftIt
+void LiquidCrystal_SR::shiftIt(uint8_t val)
 {
-   uint8_t val1, val2;
-   
-   // If _two_wire - clear the shiftregister first.
-   // ----------------------------------------------
-   if ( _two_wire ) 
+   if (_two_wire)
    {
-	   // clear fast
-	   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit);
+      // Clear to get Enable LOW
+      fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit);
    }
-   
-   // 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
-   
-   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit, val1, MSBFIRST);
-   
-   // 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.
-   fio_digitalWrite_HIGH(_srEnableRegister, _srEnableBit);
-   waitUsec( 1 );                 // enable pulse must be >450ns
-   fio_digitalWrite_SWITCHTO(_srEnableRegister, _srEnableBit,LOW);
-
-   // clear shiftregister
-   // ---------------------------
-   if ( _two_wire ) 
-   {
-	   // Clear fast
-	   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit);
-   }
-   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit, val2, MSBFIRST);
-   
-   // LCD ENABLE PULSE, se above comment
-   fio_digitalWrite_SWITCHTO(_srEnableRegister, _srEnableBit,HIGH);
-   waitUsec( 1 );                 // enable pulse must be >450ns
-   fio_digitalWrite_SWITCHTO(_srEnableRegister, _srEnableBit,LOW);
-   waitUsec( 40 );                // commands need > 37us to settle
-}
-
-//
-// write4bits
-void LiquidCrystal_SR::write4bits(uint8_t value) 
-{
-   uint8_t val1;
-   
-   // clear shiftregister
-   // --------------------------
-   if ( _two_wire ) 
-   {
-	   // clear fast
-	   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit);
-   }
-   fio_digitalWrite(_srEnableRegister, _srEnableBit, LOW);
-
-   // Discard lower nibble
-   // and format it for shiftregister output wiring to the LCD
-   val1 = SR_EN_BIT | ((value >> 1) & 0x78);
-   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit, val1, MSBFIRST);
+   fio_shiftOut(_srDataRegister, _srDataBit, _srClockRegister, _srClockBit, val, MSBFIRST);
 
    // LCD ENABLE PULSE
    //
    // 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.
-   
-   fio_digitalWrite(_srEnableRegister, _srEnableBit, HIGH);
 
-   waitUsec( 1 );                 // enable pulse must be >450ns
-   fio_digitalWrite(_srEnableRegister, _srEnableBit, LOW);
-   
-   waitUsec( 40 );               // commands need > 37us to settle
+   fio_digitalWrite_HIGH(_srEnableRegister, _srEnableBit);
+   waitUsec(1);                 // enable pulse must be >450ns
+   fio_digitalWrite_SWITCHTO(_srEnableRegister, _srEnableBit, LOW);
+   waitUsec(40);                // commands need > 37us to settle
 }
+
+// PUBLIC METHODS
+// ---------------------------------------------------------------------------
+
+
+/************ low level data pushing commands **********/
+
+// send
+void LiquidCrystal_SR::send(uint8_t value, uint8_t mode)
+{
+   // 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
+}

File LiquidCrystal_SR.h

     */
    void init ( uint8_t srdata, uint8_t srclock, uint8_t enable, uint8_t lines, 
               uint8_t font );
+   
    /*!
-    @method     
-    @abstract   For sending data when initializing the display to 4-bit
-    @discussion Initializes the LCD pin allocation and configuration.
+    * @method
+    * @abstract takes care of shifting and the enable pulse
     */
-   void write4bits ( uint8_t );
-   
+   void shiftIt (uint8_t val);
+
    uint8_t _enable_pin;  // Enable Pin
    uint8_t _two_wire;    // two wire mode
 

File examples/HelloWorld_4bit/HelloWorld_4bit.ino

+#include <Wire.h>
+#include <LiquidCrystal.h>
+
+
+LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+#define   CONTRAST_PIN   9
+#define   BACKLIGHT_PIN  7
+#define   CONTRAST       100
+
+// Creat a set of new characters
+byte smiley[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b10001,
+  0b01110,
+  0b00000
+};
+
+byte armsUp[8] = {
+  0b00100,
+  0b01010,
+  0b00100,
+  0b10101,
+  0b01110,
+  0b00100,
+  0b00100,
+  0b01010
+};
+
+byte frownie[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b00000,
+  0b01110,
+  0b10001
+};
+
+void setup()
+{
+  Serial.begin ( 57600 );
+
+  // Switch on the backlight and LCD contrast levels
+  pinMode(CONTRAST_PIN, OUTPUT);
+  pinMode(BACKLIGHT_PIN, OUTPUT);
+
+  digitalWrite(BACKLIGHT_PIN, HIGH);
+  analogWrite (CONTRAST_PIN, CONTRAST);
+    
+  lcd.begin(16,2);               // initialize the lcd 
+
+  lcd.createChar (0, smiley);    // load character to the LCD
+  lcd.createChar (1, armsUp);    // load character to the LCD
+  lcd.createChar (2, frownie);   // load character to the LCD
+
+  lcd.home ();                   // go home
+  lcd.print("Hello, ARDUINO ");  
+  lcd.setCursor ( 0, 1 );        // go to the next line
+  lcd.print (" FORUM - fm   ");      
+}
+
+void loop()
+{
+  // Do a little animation by writing to the same location
+  lcd.setCursor ( 14, 1 );
+  lcd.print (char(2));
+  delay (200);
+  lcd.setCursor ( 14, 1 );
+  lcd.print ( char(0));
+  delay (200);
+}

File examples/HelloWorld_4bit/HelloWorld_4bit.pde

-#include <Wire.h>
-#include <LiquidCrystal.h>
-
-
-LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
-#define   CONTRAST_PIN   9
-#define   BACKLIGHT_PIN  7
-#define   CONTRAST       100
-
-// Creat a set of new characters
-byte smiley[8] = {
-  0b00000,
-  0b00000,
-  0b01010,
-  0b00000,
-  0b00000,
-  0b10001,
-  0b01110,
-  0b00000
-};
-
-byte armsUp[8] = {
-  0b00100,
-  0b01010,
-  0b00100,
-  0b10101,
-  0b01110,
-  0b00100,
-  0b00100,
-  0b01010
-};
-
-byte frownie[8] = {
-  0b00000,
-  0b00000,
-  0b01010,
-  0b00000,
-  0b00000,
-  0b00000,
-  0b01110,
-  0b10001
-};
-
-void setup()
-{
-  Serial.begin ( 57600 );
-
-  // Switch on the backlight and LCD contrast levels
-  pinMode(CONTRAST_PIN, OUTPUT);
-  pinMode(BACKLIGHT_PIN, OUTPUT);
-
-  digitalWrite(BACKLIGHT_PIN, HIGH);
-  analogWrite (CONTRAST_PIN, CONTRAST);
-    
-  lcd.begin(16,2);               // initialize the lcd 
-
-  lcd.createChar (0, smiley);    // load character to the LCD
-  lcd.createChar (1, armsUp);    // load character to the LCD
-  lcd.createChar (2, frownie);   // load character to the LCD
-
-  lcd.home ();                   // go home
-  lcd.print("Hello, ARDUINO ");  
-  lcd.setCursor ( 0, 1 );        // go to the next line
-  lcd.print (" FORUM - fm   ");      
-}
-
-void loop()
-{
-  // Do a little animation by writing to the same location
-  lcd.setCursor ( 14, 1 );
-  lcd.print (char(2));
-  delay (200);
-  lcd.setCursor ( 14, 1 );
-  lcd.print ( char(0));
-  delay (200);
-}

File examples/HelloWorld_i2c/HelloWorld_i2c.ino

+#include <Wire.h> 
+#include <LiquidCrystal_I2C.h>
+
+LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address
+
+#define BACKLIGHT_PIN     13
+
+// Creat a set of new characters
+const uint8_t charBitmap[][8] = {
+   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
+   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
+   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
+   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
+   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
+   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
+   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
+   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
+   
+};
+
+void setup()
+{
+   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
+
+  // Switch on the backlight
+  pinMode ( BACKLIGHT_PIN, OUTPUT );
+  digitalWrite ( BACKLIGHT_PIN, HIGH );
+  
+  lcd.begin(16,2);               // initialize the lcd 
+
+   for ( int i = 0; i < charBitmapSize; i++ )
+   {
+      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
+   }
+
+  lcd.home ();                   // go home
+  lcd.print("Hello, ARDUINO ");  
+  lcd.setCursor ( 0, 1 );        // go to the next line
+  lcd.print (" FORUM - fm   ");
+  delay ( 1000 );
+}
+
+void loop()
+{
+   lcd.home ();
+   // Do a little animation by writing to the same location
+   for ( int i = 0; i < 2; i++ )
+   {
+      for ( int j = 0; j < 16; j++ )
+      {
+         lcd.print (char(random(7)));
+      }
+      lcd.setCursor ( 0, 1 );
+   }
+   delay (200);
+}

File examples/HelloWorld_i2c/HelloWorld_i2c.pde

-#include <Wire.h> 
-#include <LiquidCrystal_I2C.h>
-
-LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address
-
-#define BACKLIGHT_PIN     13
-
-// Creat a set of new characters
-const uint8_t charBitmap[][8] = {
-   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
-   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
-   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
-   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
-   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
-   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
-   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
-   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
-   
-};
-
-void setup()
-{
-   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
-
-  // Switch on the backlight
-  pinMode ( BACKLIGHT_PIN, OUTPUT );
-  digitalWrite ( BACKLIGHT_PIN, HIGH );
-  
-  lcd.begin(16,2);               // initialize the lcd 
-
-   for ( int i = 0; i < charBitmapSize; i++ )
-   {
-      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
-   }
-
-  lcd.home ();                   // go home
-  lcd.print("Hello, ARDUINO ");  
-  lcd.setCursor ( 0, 1 );        // go to the next line
-  lcd.print (" FORUM - fm   ");
-  delay ( 1000 );
-}
-
-void loop()
-{
-   lcd.home ();
-   // Do a little animation by writing to the same location
-   for ( int i = 0; i < 2; i++ )
-   {
-      for ( int j = 0; j < 16; j++ )
-      {
-         lcd.print (char(random(7)));
-      }
-      lcd.setCursor ( 0, 1 );
-   }
-   delay (200);
-}

File examples/SerialDisplay/SerialDisplay.ino

+/*
+ * Displays text sent over the serial port (e.g. from the Serial Monitor) on
+ * an attached LCD.
+ */
+#include <Wire.h> 
+#include <LiquidCrystal_I2C.h>
+
+#define BACKLIGHT_PIN     13
+
+LiquidCrystal_I2C lcd(0x38);  // set the LCD address to 0x38
+
+void setup()
+{
+  pinMode ( BACKLIGHT_PIN, OUTPUT );
+  lcd.begin (16,2); 
+  digitalWrite ( BACKLIGHT_PIN, HIGH );
+  
+  Serial.begin(57600);
+}
+
+void loop()
+{
+  // when characters arrive over the serial port...
+  if (Serial.available()) 
+  {
+    // wait a bit for the entire message to arrive
+    delay(100);
+    // clear the screen
+    lcd.clear();
+    // read all the available characters
+    while (Serial.available() > 0) 
+    {
+      // display each character to the LCD
+      lcd.write(Serial.read());
+    }
+  }
+}

File examples/SerialDisplay/SerialDisplay.pde

-/*
- * Displays text sent over the serial port (e.g. from the Serial Monitor) on
- * an attached LCD.
- */
-#include <Wire.h> 
-#include <LiquidCrystal_I2C.h>
-
-#define BACKLIGHT_PIN     13
-
-LiquidCrystal_I2C lcd(0x38);  // set the LCD address to 0x38
-
-void setup()
-{
-  pinMode ( BACKLIGHT_PIN, OUTPUT );
-  lcd.begin (16,2); 
-  digitalWrite ( BACKLIGHT_PIN, HIGH );
-  
-  Serial.begin(57600);
-}
-
-void loop()
-{
-  // when characters arrive over the serial port...
-  if (Serial.available()) 
-  {
-    // wait a bit for the entire message to arrive
-    delay(100);
-    // clear the screen
-    lcd.clear();
-    // read all the available characters
-    while (Serial.available() > 0) 
-    {
-      // display each character to the LCD
-      lcd.write(Serial.read());
-    }
-  }
-}

File examples/i2cLCDextraIO/i2cLCDextraIO.pde

 
 #ifdef _LCD_4BIT_
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+#endif
 const int    CONTRAST_PIN  = 9;
 const int    CONTRAST      = 65;
-#endif
+
 
 
 LCD *myLCD = &lcd;

File keywords.txt

 # Datatypes (KEYWORD1)
 ###########################################
 
-LiquidCrystal_SR	 KEYWORD1
-LiquidCrystal_I2C    KEYWORD1
-LiquidCrystal        KEYWORD1
-LCD                  KEYWORD1
+LiquidCrystal_SR	 	KEYWORD1
+LiquidCrystal_I2C    	KEYWORD1
+LiquidCrystal_SR_LCD3	KEYWORD1
+LiquidCrystal        	KEYWORD1
+LCD                  	KEYWORD1
 
 ###########################################
 # Methods and Functions (KEYWORD2)
 noCursor             KEYWORD2
 cursor               KEYWORD2
 scrollDisplayLeft    KEYWORD2
-scrollDisplayRight	KEYWORD2
+scrollDisplayRight   KEYWORD2
 leftToRight          KEYWORD2
 rightToLeft          KEYWORD2
 autoscroll           KEYWORD2