John Bailey / freetronicsLCDShield

Fork of freetronicsLCDShield by Koen Kempeneers

Files at this revision

API Documentation at this revision

Comitter:
KKempeneers
Date:
Sun Oct 27 07:07:53 2013 +0000
Parent:
0:01f3d38f8b6d
Child:
2:f40a5df43d09
Commit message:
A basic library for the Freetronics arduino LCD shield. The library is primarily targeted for the KL25Z mbed enabled microcontrollers, that is all hardware definitions default to the ports that correspond to the LCD shield 's arduino footprint.

Changed in this revision

freetronicsLCDShield.cpp Show annotated file Show diff for this revision Revisions of this file
freetronicsLCDShield.h Show annotated file Show diff for this revision Revisions of this file
--- a/freetronicsLCDShield.cpp	Tue Oct 08 08:46:39 2013 +0000
+++ b/freetronicsLCDShield.cpp	Sun Oct 27 07:07:53 2013 +0000
@@ -1,3 +1,25 @@
+/* mbed freetronicsLCDShield Library, written by Koen J.F. Kempeneers
+ * koen.kempeneers@damiaaninstituut.be
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #include "mbed.h"
 #include "freetronicsLCDShield.h"
 
@@ -54,11 +76,17 @@
     writeCommand(0x0C + tmp);
 }
 
-void freetronicsLCDShield::shift (bool left) {
-    int tmp = 0;
-    
-    if (left) tmp = 0x04;
-    writeCommand(0x18 + tmp);
+void freetronicsLCDShield::shift(bool direction) {
+    if(direction == LEFT) shiftLeft();
+    else shiftRight();
+}
+
+void freetronicsLCDShield::shiftLeft(void) {
+    writeCommand(0x18 + 0x04);
+}
+
+void freetronicsLCDShield::shiftRight(void) {
+    writeCommand(0x18);
 }
 
 void freetronicsLCDShield::cls(void) {
@@ -73,6 +101,16 @@
     wait(0.00164f);
 }
 
+void freetronicsLCDShield::writeCGRAM (char address, const char *ptr, char nbytes) {
+    // Write the address only once, it is autoincremented 
+    writeCommand(0x40 | address);
+
+    // Write the data
+    for(int i = 0; i < nbytes; i++) {
+        writeData(*ptr++);
+    }
+}
+
 // Low level output functions
 void freetronicsLCDShield::writeByte (int byte) {
     // Split the byte in high and low nibble, write high nibble first
--- a/freetronicsLCDShield.h	Tue Oct 08 08:46:39 2013 +0000
+++ b/freetronicsLCDShield.h	Sun Oct 27 07:07:53 2013 +0000
@@ -1,3 +1,28 @@
+/* mbed freetronicsLCDShield Library, written by Koen J.F. Kempeneers
+ * koen.kempeneers@damiaaninstituut.be
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef FREETRONICSLCDSHIELD_H
+#define FREETRONICSLCDSHIELD_H
+
 #define LEFT  0
 #define RIGHT 1
 
@@ -26,11 +51,14 @@
                               PinName bl = PTA12,
                               PinName a0 = PTB0);                               
                               
+        void writeCGRAM (char address, const char *ptr, char nbytes);
         void setCursorPosition (int line, int col);
         void setBackLight (bool blStatus);
         void setBackLight (float blIntensity);
-        void setCursor (bool cStatus, bool blink = false);
-        void shift (bool left); 
+        void setCursor (bool cStatus = true, bool blink = false);
+        void shiftLeft (void);
+        void shiftRight (void);
+        void shift (bool direction);
         void cls (void);
         void home(void);
         
@@ -40,4 +68,6 @@
         // Stream implementation functions
         virtual int _putc(int value);
         virtual int _getc();
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file