added lcd.start()

Fork of TextLCD by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
ritarosakai
Date:
Mon Jan 08 07:21:35 2018 +0000
Parent:
8:308d188a2d3a
Child:
10:cec91d426d65
Commit message:
Added lcd.start()

Changed in this revision

TextLCD.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.h Show annotated file Show diff for this revision Revisions of this file
--- a/TextLCD.cpp	Thu Jan 02 21:07:01 2014 +0000
+++ b/TextLCD.cpp	Mon Jan 08 07:21:35 2018 +0000
@@ -25,9 +25,13 @@
 
 TextLCD::TextLCD(PinName rs, PinName e, PinName d4, PinName d5,
                  PinName d6, PinName d7, LCDType type) : _rs(rs),
-        _e(e), _d(d4, d5, d6, d7),
-        _type(type) {
+    _e(e), _d(d4, d5, d6, d7),
+    _type(type)
+{
+}
 
+void TextLCD::start()
+{
     _e  = 1;
     _rs = 0;            // command mode
 
@@ -47,24 +51,44 @@
     cls();
 }
 
-void TextLCD::character(int column, int row, int c) {
+void TextLCD::character(int column, int row, int c)
+{
     int a = address(column, row);
     writeCommand(a);
     writeData(c);
 }
 
-void TextLCD::cls() {
+void TextLCD::cls()
+{
+    _e  = 1;
+    _rs = 0;            // command mode
+
+    wait(0.015);        // Wait 15ms to ensure powered up
+
+    // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+    for (int i=0; i<3; i++) {
+        writeByte(0x3);
+        wait(0.00164);  // this command takes 1.64ms, so wait for it
+    }
+    writeByte(0x2);     // 4-bit mode
+    wait(0.000040f);    // most instructions take 40us
+
+    writeCommand(0x28); // Function set 001 BW N F - -
+    writeCommand(0x0C);
+    writeCommand(0x6);  // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
     writeCommand(0x01); // cls, and set cursor to 0
     wait(0.00164f);     // This command takes 1.64 ms
     locate(0, 0);
 }
 
-void TextLCD::locate(int column, int row) {
+void TextLCD::locate(int column, int row)
+{
     _column = column;
     _row = row;
 }
 
-int TextLCD::_putc(int value) {
+int TextLCD::_putc(int value)
+{
     if (value == '\n') {
         _column = 0;
         _row++;
@@ -85,11 +109,13 @@
     return value;
 }
 
-int TextLCD::_getc() {
+int TextLCD::_getc()
+{
     return -1;
 }
 
-void TextLCD::writeByte(int value) {
+void TextLCD::writeByte(int value)
+{
     _d = value >> 4;
     wait(0.000040f); // most instructions take 40us
     _e = 0;
@@ -102,17 +128,20 @@
     _e = 1;
 }
 
-void TextLCD::writeCommand(int command) {
+void TextLCD::writeCommand(int command)
+{
     _rs = 0;
     writeByte(command);
 }
 
-void TextLCD::writeData(int data) {
+void TextLCD::writeData(int data)
+{
     _rs = 1;
     writeByte(data);
 }
 
-int TextLCD::address(int column, int row) {
+int TextLCD::address(int column, int row)
+{
     switch (_type) {
         case LCD20x4:
             switch (row) {
@@ -134,7 +163,8 @@
     }
 }
 
-int TextLCD::columns() {
+int TextLCD::columns()
+{
     switch (_type) {
         case LCD20x4:
         case LCD20x2:
@@ -146,7 +176,8 @@
     }
 }
 
-int TextLCD::rows() {
+int TextLCD::rows()
+{
     switch (_type) {
         case LCD20x4:
             return 4;
--- a/TextLCD.h	Thu Jan 02 21:07:01 2014 +0000
+++ b/TextLCD.h	Mon Jan 08 07:21:35 2018 +0000
@@ -32,15 +32,16 @@
  * @code
  * #include "mbed.h"
  * #include "TextLCD.h"
- * 
+ *
  * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
- * 
+ *
  * int main() {
  *     lcd.printf("Hello World!\n");
  * }
  * @endcode
  */
-class TextLCD : public Stream {
+class TextLCD : public Stream
+{
 public:
 
     /** LCD panel format */
@@ -84,7 +85,7 @@
 
     /** Clear the screen and locate to 0,0 */
     void cls();
-
+    void start();
     int rows();
     int columns();