liamgrazier lcd library 16x02

Dependents:   Final351CW_FINAL

Fork of LGLCDv2 by Liam Grazier

Files at this revision

API Documentation at this revision

Comitter:
liam_grazier
Date:
Tue Jan 09 11:32:39 2018 +0000
Parent:
1:9020af47a312
Commit message:
V9.9

Changed in this revision

lglcd.cpp Show annotated file Show diff for this revision Revisions of this file
lglcd.h Show annotated file Show diff for this revision Revisions of this file
--- 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);
+        }
+    }   
 }
--- a/lglcd.h	Fri Jan 05 17:56:27 2018 +0000
+++ b/lglcd.h	Tue Jan 09 11:32:39 2018 +0000
@@ -1,37 +1,35 @@
-#ifndef __LGLCD_H
+/*   ELEC351 COURSEWORK 2018 
+DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL
+LIAM GRAZIER // DOUG TILLEY // ALEX BARON 
+ */
+#ifndef __LGLCD_H 
 #define __LGLCD_H
-
-#define CMD          0
-#define TXT          1
-#define CLEAR        1
-#define HOME         2
-#define READ         1
+#define CMD      0 //adapted from 2nd year code
+#define TXT      1
+#define CLEAR    1
+#define HOME     2
+#define READ     1
 #define WRITE    0
-#define LEFT         0
+#define LEFT     0
 #define RIGHT    1
-
 #define LINE1    0x80        // Start address of first line
 #define LINE2    0xC0        // Start address of second line
-
 #define LCD_CLR             (writedata(CLEAR,CMD))
 #define LCD_HOME            (writedata(HOME,CMD))
 #define LCD_BUSYBIT 0x8000  //correct value for the lcd BUSYBIT
-
-
+//mylcdclass 
 class lglcd
 {
 public:
-lglcd(PinName rs, PinName e, PinName d4, PinName d5,PinName d6, PinName d7);
-void clear(void);
-void writedata(unsigned char info, unsigned char type);
-void lglcd::setline(int row,int column);
-void write(char charq[]);
-int l;
+lglcd(PinName RS, PinName E, PinName D4, PinName D5,PinName D6, PinName D7); //statement for pin enables
+void clear(void); //function for clearlcd
+void writedata(unsigned char info, unsigned char type); //function forwiring data on the screen 
+void lglcd::setline(int row,int column); //setline command row/column
+void write(char charq[]); //wirint char/str on mylcd.
+int l; 
 protected:
-BusOut _lcdinfo;
-DigitalOut _lcdrs;
-DigitalOut _lcde;
-int cline;
-int cpos;
+BusOut _lcdinfo; //output define for D4-D7
+DigitalOut _lcdrs; //output define for RS Pin
+DigitalOut _lcde; //output define for E pin
 };
 #endif
\ No newline at end of file