liamgrazier lcd library 16x02

Dependents:   Final351CW_FINAL

Fork of LGLCDv2 by Liam Grazier

Revision:
2:d812a2a643bc
Parent:
1:9020af47a312
diff -r 9020af47a312 -r d812a2a643bc lglcd.cpp
--- a/lglcd.cpp	Fri Jan 05 17:56:27 2018 +0000
+++ b/lglcd.cpp	Tue Jan 09 11:32:39 2018 +0000
@@ -1,84 +1,81 @@
+/*   ELEC351 COURSEWORK 2018 
+DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL
+LIAM GRAZIER // DOUG TILLEY // ALEX BARON 
+ */
 #include "mbed.h"
 #include "lglcd.h"
-
-lglcd::lglcd(PinName rs, PinName e, PinName d4, PinName d5,PinName d6, PinName d7) : _lcdrs(rs),_lcde(e), _lcdinfo(d4, d5, d6, d7)
+lglcd::lglcd(PinName RS, PinName E, PinName D4, PinName D5,PinName D6, PinName D7) : _lcdrs(RS),_lcde(E), _lcdinfo(D4, D5, D6, D7)
 {
-    cline=1; //set the current line to the top line
-    cpos=0; //sets the current position to the left most CHARACTER
-    _lcde=1;              //clear enable
+       _lcde=1;              //clear enable
     _lcdrs=0;             // command
-    l = 0;
     writedata(_lcde,CMD);
-    wait(0.000004);              //delay for LCD to initialise.
-    writedata(0x28,CMD);         //set to 4 bit interface, 2 line and 5*8 font
+    wait(0.000004);              
+    writedata(0x28,CMD);         
     wait(0.000004);
-    writedata(0x0C,CMD);         //cursor on, cursor position blink
+    writedata(0x0C,CMD);      //turnoncursor and blink
     wait(0.000004);
     writedata(0x10,CMD);
     wait(0.000004);
-    LCD_CLR;                        //clear display
+    LCD_CLR;                 //clearlcd
     wait(0.000004);
-    writedata(0x06,CMD);         //move cursor right after write
+    writedata(0x06,CMD);     //movecursor right
     wait(0.000004);
-    LCD_HOME;                                   //return home
-
+    LCD_HOME;               //Return to the 0,0 
 }
-/*---------------------------------------------------------------------*/
-void lglcd::clear(void)//set a function to clear the lcd since just calling LCD_CLR can throw error if called to quickly
+void lglcd::clear(void)//lcd clear command with a tiny wait to ensure commadn finishes 
 {
-    LCD_CLR;
-    wait(0.002); //2ms delay to stop timing error
+    LCD_CLR;             //clearcommandwitha small wait
+    wait(0.002); 
 }
-void lglcd::setline(int row,int column)
+void lglcd::setline(int row,int column) //set lu=ine and column function
 {   
-    if(row == 1) { // switch statement for placing the cursor
-                    writedata(LINE1|column,CMD); //set lcd to line one and correct position
-            wait(0.005); //2ms delay to stop empty screen timing error
+    if(row == 1) 
+    { 
+        writedata(LINE1|column,CMD);  //line1 included 
+        wait(0.005); 
     }
-    if(row == 2){
-            writedata(LINE2|column,CMD); //set lcd to line two and correct position
-            wait(0.005); //2ms delay to stop empty screen timing error
-      }
+    if(row == 2)
+    {
+        writedata(LINE2|column,CMD); 
+        wait(0.005); 
     }
-
-/*---------------------------------------------------------------------*/
-void lglcd::writedata(unsigned char info, unsigned char type)
+}
+void lglcd::writedata(unsigned char data, unsigned char type) //manual write data wherever the pointer is , requires the line to be set first .
 {
     if(type == CMD) 
     {
-        _lcdrs=0;              //COMMAND MODE
-    }
-     else
-      {
-        _lcdrs=1;          //CHARACTER/DATA MODE
+        _lcdrs=0;          //COMMAND MODE
     }
-    
-    _lcdinfo = info >> 4;
-    wait(0.000040f); // most instructions take 40us
+    else
+    {
+        _lcdrs=1;          //CHARACTER/DATA MODE
+    } 
+    _lcdinfo = data >> 4;
+    wait(0.000050f); 
     _lcde = 0;
-    wait(0.000040f);
+    wait(0.000050f);
     _lcde = 1;
-    _lcdinfo = info >> 0;
-    wait(0.000040f);
+    _lcdinfo = data >> 0;
+    wait(0.000050f);
     _lcde = 0;
-    wait(0.000040f);  // most instructions take 40us
+    wait(0.000050f);
     _lcde = 1;
 }
-
-void lglcd::write(char charq[])
+void lglcd::write(char charq[]) //write character, not used, used writedata mainly, this works well if need to write along string to 2 lines (FOR LOOP FOR CHANING LINE AUTO) 
 { 
- for (int i = 0; i < strlen(charq); i++)
-  {
-    wait(0.003);
-    int count = 0;
-    count++;
-    writedata(charq[i], TXT);
-    if (i == 15) {
-      writedata(LINE2 | 0, CMD);
-    }
-    if (i == 32) {
-      clear();
-      writedata(LINE1, CMD);
-   }
-  }
+    for (int n = 0; n < strlen(charq); n++)
+    {
+        int count = 0;
+        count++;
+        writedata(charq[n], TXT);
+        if (n == 15)
+        {
+            writedata(LINE2 | 0, CMD);
+        }
+        if (n == 32) 
+        {
+            clear();
+            writedata(LINE1, CMD);
+        }
+    }   
 }