Nelson Oliveira / Mbed 2 deprecated LCD

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
nelsonoliveira
Date:
Thu Sep 27 20:28:05 2012 +0000
Parent:
0:329ba18c901d
Commit message:
Now with options for baud rate and custom splash

Changed in this revision

SparkfunSerialLCD.cpp Show annotated file Show diff for this revision Revisions of this file
SparkfunSerialLCD.h Show annotated file Show diff for this revision Revisions of this file
example.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SparkfunSerialLCD.cpp	Mon Jan 10 21:23:15 2011 +0000
+++ b/SparkfunSerialLCD.cpp	Thu Sep 27 20:28:05 2012 +0000
@@ -9,10 +9,15 @@
 #include "SparkfunSerialLCD.h"
 #include "mbed.h"
 #include "stdarg.h"
-
- SparkfunSerialLCD::SparkfunSerialLCD(PinName tx): _lcd(tx,NC)
+   
+SparkfunSerialLCD::SparkfunSerialLCD(PinName tx, int baud, bool clrError): _lcd(tx,NC)
 {
-    wait_ms(500);   //Gives the serial module time to wakeup
+    if (clrError)
+    {
+        SendCmd(Target::Module, Cmd::ResetUnit);
+    }
+    wait(1);        //Gives the serial module time to wakeup
+    setBaud(baud);  //Changes the baud
     cls();          //Clears the screen
     Backlight(29);  //Default backlight
 }
@@ -52,3 +57,40 @@
 {
     SendCmd(Target::Module, bright+128);    //Adjusts bright to conform to serial module needs and sends instruction
 }
+
+void SparkfunSerialLCD::setSplash()
+{
+    SendCmd(Target::Module, Cmd::SetSplash);//Sets the current text as the splash screen
+}
+
+void SparkfunSerialLCD::setBaud(int baud)
+{
+    //Changes baud, defaults to 9600 in case of invalid value
+    switch (baud)
+    {
+        case 2400:
+            SendCmd(Target::Module, Cmd::b2400);
+            _lcd.baud(baud);
+            break;
+        case 4800:
+            SendCmd(Target::Module, Cmd::b4800);
+            _lcd.baud(baud);
+            break;
+        case 14400:
+            SendCmd(Target::Module, Cmd::b14400);
+            _lcd.baud(baud);
+            break;
+        case 19200:
+            SendCmd(Target::Module, Cmd::b19200);
+            _lcd.baud(baud);
+            break;
+        case 38400:
+            SendCmd(Target::Module, Cmd::b38400);
+            _lcd.baud(baud);
+            break;
+        default:
+            SendCmd(Target::Module, Cmd::b9600);
+            _lcd.baud(9600);
+            break;
+    }
+}
\ No newline at end of file
--- a/SparkfunSerialLCD.h	Mon Jan 10 21:23:15 2011 +0000
+++ b/SparkfunSerialLCD.h	Thu Sep 27 20:28:05 2012 +0000
@@ -13,12 +13,17 @@
 
 class SparkfunSerialLCD
 {
-public:
+private:
     //Direct access to the serial connection
     Serial _lcd;
-    
-    //Constructor only asks for mbed TX pin, choose from list -> {9,13,28}
-    SparkfunSerialLCD(PinName tx);
+public:
+    /**
+     * Constructor:
+     * tx           TX pin (choose from list -> {9,13,28}) and an optional baud rate
+     * baud         The baud rate for the LCD (optional, defaults to 9600)
+     * clsError     Resets the LCD to defaults (must use immediatly after power on)
+     */
+    SparkfunSerialLCD(PinName tx, int baud = 9600, bool clrError = false);
 
     //basic functions
     void SendCmd(int target, int cmd);      //Send special commands (see tables below)
@@ -26,6 +31,8 @@
     void print(const char *msg);            //Sends message to screen
     void printf(const char *msg, ...);      //Sends formated message to screen
     void cls();                             //Clear screen
+    void setSplash();                       //Sets the current text as the splash screen
+    void setBaud(int baud);                 //Changes the LCD baud rate, defaults to 9600 in case of invalid value
 
     //Adjusts Backlight -> bright: 0 to 29 (darker to brighter)
     void Backlight(int bright);
@@ -47,6 +54,14 @@
             BlinkingCursorOn    = 0x0D,
             BlinkingCursorOff   = 0x0C,
             CursorPos           = 0x80,
+            ResetUnit           = 0x11,
+            SetSplash           = 0x0A,
+            b2400               = 0x0B, //These lines stating with "b" are the baud rates
+            b4800               = 0x0C,
+            b9600               = 0x0D,
+            b14400              = 0x0E,
+            b19200              = 0x0F,
+            b38400              = 0x10
         };
     };
     
--- a/example.cpp	Mon Jan 10 21:23:15 2011 +0000
+++ b/example.cpp	Thu Sep 27 20:28:05 2012 +0000
@@ -10,7 +10,7 @@
 #include "SparkfunSerialLCD.h"
 
 //Declares a SparkFun Serial LCD on mbed pin 13
-SparkfunSerialLCD LCD(p13);
+SparkfunSerialLCD LCD(p13, 38400, true);
 
 int main()
 {
@@ -21,7 +21,7 @@
     LCD.print("LCD");
     
     wait(2);                //Leaves message on screen for 2 seconds
-
+    
     while (1)               //Eternal loop
     {
         LCD.cls();                      //Clear screen