Dependents:   vmConfort_v6 Programski_zadatak_23 Projektni_zadatak_23 tempivolt

Files at this revision

API Documentation at this revision

Comitter:
RichardUK
Date:
Sun Apr 08 12:51:51 2012 +0000
Parent:
0:6c0e68e0d876
Commit message:
Fixed a bug in the printf func.
Added comments.

Changed in this revision

Display1602.cpp Show annotated file Show diff for this revision Revisions of this file
Display1602.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6c0e68e0d876 -r fc4c861451e1 Display1602.cpp
--- a/Display1602.cpp	Fri Apr 06 19:22:15 2012 +0000
+++ b/Display1602.cpp	Sun Apr 08 12:51:51 2012 +0000
@@ -2,7 +2,7 @@
 #include "Display1602.h"
 
  Display1602::Display1602(PinName registerSelect,PinName readWriteSelect,PinName readWriteEnable,PinName d0,PinName d1,PinName d2,PinName d3,PinName d4,PinName d5,PinName d6,PinName d7) 
-        : rs(registerSelect), rw(readWriteSelect), e(readWriteEnable), bf(d7), data(d0,d1,d2,d3,d4,d5,d6,d7)
+        : rs(registerSelect), rw(readWriteSelect), e(readWriteEnable), data(d0,d1,d2,d3,d4,d5,d6,d7)
 {
     //To ensure we have waited 15ms after power up and VDD > 4.5v (don't know how to test VDD)
     wait_ms(20);
@@ -12,7 +12,7 @@
     
     //Set interface to 8 bit mode
     SendCommand(0x38);
-   wait_ms(1); 
+    wait_ms(1); 
     
     //Display off
     SendCommand(0x08);
@@ -37,21 +37,21 @@
 
 void Display1602::Print(const char *text)
 {
-	int n = 16;
-	while (*text && n--)
-	{
-		SendChar(*text);
-		text++;
-	}
+    int n = 16;
+    while (*text && n--)
+    {
+        SendChar(*text);
+        text++;
+    }
 }
 
 void Display1602::printf(const char *format,...)
 {
     va_list args;
-    char buf[16];
+    char buf[17];
 
     va_start(args, format);
-    vsnprintf(buf,16,format, args);
+    vsnprintf(buf,17,format, args);
     va_end(args);
     
     Print(buf);        
@@ -59,14 +59,14 @@
 
 void Display1602::SetXY(int x,int y)
 {
-	if (y == 0)
-	{
-		SendCommand (0x80 | x);
-	}
-	else
-	{
-		SendCommand (0xC0 | x);
-	}
+    if (y == 0)
+    {
+        SendCommand (0x80 | x);
+    }
+    else
+    {
+        SendCommand (0xC0 | x);
+    }
 }
     
 void Display1602::SendCommand(int cmd)
diff -r 6c0e68e0d876 -r fc4c861451e1 Display1602.h
--- a/Display1602.h	Fri Apr 06 19:22:15 2012 +0000
+++ b/Display1602.h	Sun Apr 08 12:51:51 2012 +0000
@@ -46,7 +46,7 @@
 
 */
 
-/*
+/** Basic bit of code for using a standard 1602 display in 8 bit mode.
  * Written by Richard e Collins.
  * Basic bit of code for using a standard 1602 display in 8 bit mode.
  * When wiring one of these displays up make sure the power to the LCD on pin 3 is correct, too high and it will not display anything. About 0.2v is good, I use a POT to set it.
@@ -58,21 +58,40 @@
  */
 struct Display1602
 {
+    /**
+     * Constructor, here you state the oins used to read and write data on and the control pins.
+     * @param registerSelect This is the pin used to select if you are sending data or setting a control register.
+     * @param readWriteSelect The pin to state if you are reading or writing data / register.
+     * @param d0 -> d7. The eight pins for the data to be either written to the display or a register.
+     */
     Display1602(PinName registerSelect,PinName readWriteSelect,PinName readWriteEnable,PinName d0,PinName d1,PinName d2,PinName d3,PinName d4,PinName d5,PinName d6,PinName d7) ;
-    
+
+    /**
+     * Clears the display.
+     */    
     void Clear();
     
+    /**
+     * Prints the text to the display, will limit the chars read by 16 chars or hitting a null terminator, which ever comes first.
+     * Advances the cursor pos.
+     */
     void Print(const char *text);
     
+    /**
+     * handy printf funtion for displaying text.
+     * Advances the cursor pos.
+     */
     void printf(const char *format,...);
 
+    /**
+     *Sets the cusor X Y pos.
+     */
     void SetXY(int x,int y);
     
 private:
     DigitalOut rs;     //Register select, high value in data is data char data, when low is a command.
     DigitalOut rw;    //Data direction, high read operation, low is write operation.
     DigitalOut e;    //When high the value in data is read from or written to the register selected. 
-    DigitalOut bf;           //Used by the hardware to say when busy, this is also data bit 7. I am assuming it is only valid to read when readWriteEnable is false.
     BusOut data;    //The data sent.
     
     void SendCommand(int cmd);