4-Line LCD Text Display. This is a simple library that can be used to print a formatted string on a 2 or 4 line Hitachi parallel display. By calling a single Method.

Files at this revision

API Documentation at this revision

Comitter:
mr63
Date:
Tue Oct 08 15:41:55 2013 +0000
Commit message:
LCD 4-Line Text Display. This is a simple library that can be used to print a formatted string on up to a 4 line display. By calling a single Method.

Changed in this revision

LCD.cpp Show annotated file Show diff for this revision Revisions of this file
LCD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 0e97b0a48eb8 LCD.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp	Tue Oct 08 15:41:55 2013 +0000
@@ -0,0 +1,91 @@
+#include "LCD.h"
+
+//LCD Class Constructor for polling A2D using int ADC0848::Poll_A2D(unsigned char Channel)
+LCD::LCD(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, PinName pin6, PinName pin7, PinName pin8, PinName pin9, PinName pin10) 
+								:_DataBus(pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8), _RS(pin9), _Enable(pin10)
+{
+	Initialize();
+}
+
+void LCD::Initialize()
+ {
+  wait(.01); 
+  _RS = 0;
+	_Enable = 0;	 //EN and RS = 0
+  wait(.001);
+  WriteLCDCmd(0x38);       //Required for initialization    
+  wait(.001);
+  WriteLCDCmd(0x38);       //Required for initialization    
+  wait(.001);
+  WriteLCDCmd(0x38);       //Required for initialization    
+  wait(.001);
+  WriteLCDCmd(0x38);       //2 rows x 16 cols 5x7 dot char    
+  wait(.001);
+  WriteLCDCmd(0x0C);       //Display on, cursor off
+  wait(.001);
+  WriteLCDCmd(0x01);       //Cursor home
+  wait(.001);
+  WriteLCDCmd(0x06);       //incr cursor and shift on
+  wait(.001);
+	wait(.1);	 
+  return;
+ }
+
+void LCD::WriteLCDData(char c, char Pos)
+ {
+  WriteLCDCmd(Pos);
+	_DataBus.output();
+  wait(.001);
+  _DataBus  = c;                    //Data to LCD Data
+  _RS = 1;
+	_Enable = 1;//RS = EN = 1
+  wait(.001);
+  _Enable = 0;            //EN = 0
+  return;
+ }
+
+void LCD::WriteLCDCmd(char c)
+ {
+	_DataBus.output();
+  _DataBus = c;              //Data to LCD data
+  _RS = 0;      //RS = 0
+  _Enable = 1;      //En = 1
+  wait(.010);
+  _Enable = 0;      //En = 0
+  return;
+ }
+ 
+ void LCD::ClearDisplay()
+  {
+   WriteLCDCmd(0x01);         // clear display
+  }
+
+	
+void LCD::Print_String(char* Pbuffer,char line_num, char offset)
+	{
+		unsigned int i=0;
+		char pos = 0;
+		switch (line_num)
+		{
+			case(1):
+				pos = 0x80+offset;
+				break;
+			case(2):
+				pos = 0xC0+offset;
+				break;
+			case(3):
+				pos = 0x94+offset;
+				break;
+			case(4):
+				pos = 0xD4+offset;
+				break;
+			default:
+				break;			
+		}
+		while (Pbuffer[i] !=  0)
+    {
+        WriteLCDData(Pbuffer[i], pos+i);  
+        i++;    
+    }
+	}
+	
\ No newline at end of file
diff -r 000000000000 -r 0e97b0a48eb8 LCD.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.h	Tue Oct 08 15:41:55 2013 +0000
@@ -0,0 +1,28 @@
+#include "MBED.h"
+
+
+
+
+
+
+class LCD {
+public:					//Strobe			//CLK					//Data
+ 
+ LCD(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, PinName pin6, PinName pin7, PinName pin8, PinName pin9, PinName pin10); 
+		void ClearDisplay();
+		void Print_String(char* Pbuffer,char line_num=1, char offset=0);
+
+
+
+private:
+
+	BusInOut _DataBus;
+  DigitalOut 		_RS;
+	DigitalOut 		_Enable;
+
+		void Initialize();
+		void WriteLCDData(char c, char Pos);
+		void WriteLCDCmd(char c);
+
+
+};
diff -r 000000000000 -r 0e97b0a48eb8 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 08 15:41:55 2013 +0000
@@ -0,0 +1,38 @@
+
+#include "LCD.h"
+#include "stdio.h"
+
+Serial pc(USBTX,USBRX);
+char msgInit[] = "Display ready";
+////////////D0--------------------------D7, RS, Enable
+LCD Display(p13,p14,p15,p16,p17,p18,p19,p20,p12,p10);
+
+int main() {
+	int count;
+	Display.ClearDisplay();
+	Display.Print_String(msgInit);
+	wait(5);
+	Display.ClearDisplay();
+	sprintf(msgInit,"Line 1: Hello");	
+	Display.Print_String(msgInit);
+	sprintf(msgInit,"Line 2: Mom");
+  Display.Print_String(msgInit,2);
+	sprintf(msgInit,"Line 3: How are");
+	Display.Print_String(msgInit,3);
+	sprintf(msgInit,"Line 4: You");
+	Display.Print_String(msgInit,4);
+	wait(10);
+  Display.ClearDisplay();
+    while(1) //Do what ever is between these brackets forever or until the micro is reset.
+			{
+				for(count=0;count<5000;count++)
+				{
+					sprintf(msgInit,"I=%d",count);	
+					Display.Print_String(msgInit,1,5);
+					wait(.5);
+				}
+				
+			}	
+}
+
+