Anonymous avatar Anonymous committed 9049dcf

SR1 example, keywords, a bit of cleanup

Comments (0)

Files changed (4)

LiquidCrystal_SR1.cpp

 // Assuming 1 line 8 pixel high font
 LiquidCrystal_SR1::LiquidCrystal_SR1 ( uint8_t srsig )
 {
-	init ( srsig );
+	// Initialise signal pin
+	_srSignalRegister = fio_pinToOutputRegister(srsig,SKIP);
+	_srSignalBit = fio_pinToBit(srsig);
+	fio_shiftOut1_init(_srSignalRegister,_srSignalBit);
+
+	// all outputs of shift register to low
+	fio_shiftOut1(_srSignalRegister, _srSignalBit, 0x00);
+
+	_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x10DOTS;
 }
 
 
 // PRIVATE METHODS
 // ---------------------------------------------------------------------------
 
-//
-// init
-void LiquidCrystal_SR1::init( uint8_t srsig )
-{
-   // Initialise private variables
-	_srSignalRegister = fio_pinToOutputRegister(srsig,SKIP);
-	_srSignalBit = fio_pinToBit(srsig);
-	fio_shiftOut1_init(_srSignalRegister,_srSignalBit);
-	// all outputs of shift register to low
-	fio_shiftOut1(_srSignalRegister, _srSignalBit, 0x00);
 
-   _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x10DOTS;
-}
 
 // PUBLIC METHODS
 // ---------------------------------------------------------------------------
 
 /************ low level data pushing commands **********/
 
+#define SR_RS_BIT		B00000100	/* = Qc */
+#define SR_EN_BIT		B10000000	/* = Qh */
+#define SR_UNUSED_BITS	B00000011	/* = Qa + Qb */
+
 // send
 void LiquidCrystal_SR1::send(uint8_t value, uint8_t mode)
 {
 	// 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
 
-	// unused outputs to high (faster)
-	val1 |= SR_UNUSED_BITS;
-	val2 |= SR_UNUSED_BITS;
-
-//	val1 |= SR_EN_BIT; // Enable high
+	// upper nibble
+	val1 = mode | ((value >> 1) /* & 0x78 */);
+	val1 |= SR_UNUSED_BITS; // unused outputs to high (faster)
+	val1 |= SR_EN_BIT; // Enable high
 	fio_shiftOut1(_srSignalRegister,_srSignalBit,val1);
 	waitUsec(1);
-
 	val1 &= ~SR_EN_BIT; // Enable low
 	fio_shiftOut1(_srSignalRegister,_srSignalBit,val1);
 	waitUsec(40);
 
-//	val2 |= SR_EN_BIT; // Enable high
+	// lower nibble
+	val2 = mode | ((value << 3) /* & 0x78 */);
+	val2 |= SR_UNUSED_BITS; // unused outputs to high (faster)
+	val2 |= SR_EN_BIT; // Enable high
 	fio_shiftOut1(_srSignalRegister,_srSignalBit,val2);
 	waitUsec(1);
-
 	val2 &= ~SR_EN_BIT; // Enable low
 	fio_shiftOut1(_srSignalRegister,_srSignalBit,val2);
 	waitUsec(40);

LiquidCrystal_SR1.h

 #include "FastIO.h"
 
 
-// two-wire indicator constant
-// ---------------------------------------------------------------------------
-#define SR_RS_BIT 0x04
-#define SR_EN_BIT 0x80
-#define SR_UNUSED_BITS 0x02
-
 class LiquidCrystal_SR1 : public LCD
 {
 public:
     The constructor does not initialize the LCD. Assuming 1 line 8 pixel high 
     font.
     
-    @param srdata[in]   pin for shiftregister data line.
-    @param srclock[in]  pin for shiftregister clock line.
-    @param enable[in]   enable pin for the shiftregister.
+    @param srsig[in]   pin for shiftregister signal line.
     */
    LiquidCrystal_SR1 ( uint8_t srsig );
    
    
    
 private:
-   
-   /*!
-    @method     
-    @abstract   Initializes the LCD pin allocation
-    @discussion Initializes the LCD pin allocation and configuration.
-    */
-   void init ( uint8_t srsig );
-   /*!
-    @method     
-    @abstract   For sending data when initializing the display to 4-bit
-    @discussion Initializes the LCD pin allocation and configuration.
-    */
-   //void write4bits ( uint8_t );
 
    // signal pin
    fio_register _srSignalRegister;

examples/HelloWorld_SR1/HelloWorld_SR1.ino

+#include <LiquidCrystal_SR1.h>
+
+LiquidCrystal_SR1 lcd(2);
+//                    |
+//                    \---- Signal Pin
+
+// Creat a set of new characters
+byte armsUp[8] = {0b00100,0b01010,0b00100,0b10101,0b01110,0b00100,0b00100,0b01010};
+byte armsDown[8] = {0b00100,0b01010,0b00100,0b00100,0b01110,0b10101,0b00100,0b01010};
+
+void setup(){
+  lcd.begin(16,2);               // initialize the lcd
+
+  lcd.createChar (0, armsUp);    // load character to the LCD
+  lcd.createChar (1, armsDown);    // load character to the LCD
+
+  lcd.home ();                   // go home
+  lcd.println(F("newLiquidCrystal"));
+
+}
+
+void loop(){
+  // Do a little animation
+  for(int i = 0; i <= 15; i++) showHappyGuy(i);
+  for(int i = 15; i >= 0; i--) showHappyGuy(i);
+}
+
+void showHappyGuy(int pos){
+  lcd.setCursor ( pos, 1 ); // go to position
+  lcd.print(char(random(0,2))); // show one of the two custom characters
+  delay(150); // wait so it can be seen
+  lcd.setCursor ( pos, 1 ); // go to position again
+  lcd.print(F(" ")); // delete character
+}
 # Datatypes (KEYWORD1)
 ###########################################
 
-LiquidCrystal_SR	 KEYWORD1
-LiquidCrystal_I2C    KEYWORD1
-LiquidCrystal        KEYWORD1
-LCD                  KEYWORD1
+LiquidCrystal_SR	    KEYWORD1
+LiquidCrystal_I2C     KEYWORD1
+LiquidCrystal         KEYWORD1
+LCD                   KEYWORD1
+LiquidCrystal_SR1     KEYWORD1
+LiquidCrystal_SR_LCD3 KEYWORD1
 
 ###########################################
 # Methods and Functions (KEYWORD2)
 noCursor             KEYWORD2
 cursor               KEYWORD2
 scrollDisplayLeft    KEYWORD2
-scrollDisplayRight	KEYWORD2
+scrollDisplayRight	 KEYWORD2
 leftToRight          KEYWORD2
 rightToLeft          KEYWORD2
 autoscroll           KEYWORD2
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.