Contains necessary classes and functions for ELEC351

/media/uploads/Luka_Danilovic/elec_315_prototype_assembly.jpg

Revision:
5:becb1545229d
Parent:
3:e84fa53173e6
diff -r d463eafbabed -r becb1545229d displayMaster/displayMaster.hpp
--- a/displayMaster/displayMaster.hpp	Thu Dec 28 12:34:20 2017 +0000
+++ b/displayMaster/displayMaster.hpp	Tue Jan 09 11:25:52 2018 +0000
@@ -1,38 +1,54 @@
 #ifndef displayMaster
 #define displayMaster
 
-#define defaultD1 D7
-#define defaultD2 D6
-#define defaultD3 D4
-#define defaultD4 D2
-#define defaultRS D9
-#define defaultRW D0
-#define defaultEN D8
+#define defaultD1 D7    // Data Bus LSB
+#define defaultD2 D6    // |
+#define defaultD3 D4    // |
+#define defaultD4 D2    // Data Bus MSB
+#define defaultRS D9    // Register Select
+#define defaultRW D0    // Read/Write Select
+#define defaultEN D8    // Enable
 
 /* Instructions on using the 16x2 LCD panel are found here:
-[https://www.8051projects.net/lcd-interfacing/lcd-4-bit.php] */
-
-/* N.B. This class contains blocking function */
+[https://www.8051projects.net/lcd-interfacing/lcd-4-bit.php]                  */
+/* N.B. I did the code from scratch since I do not have the code from ELEC230 */
+/* N.B. This class contains blocking function so it goes into its own thread  */
 
-class C_displayMaster // Custom 16x2 LCD display driver (4 bit mode only)
+// Custom 16x2 LCD display driver (4 bit mode only). Works via character stream
+class C_displayMaster: public Stream 
 {
-    private:
+protected:
+    
+    // Control line commands
     enum REGISTER {INSTRUCTION, DATA};
     enum MODE     {WRITE, READ};
-    enum ENABLE   {DISABLE, ENABLE};
-    
+    enum VALIDATE {DISABLE, ENABLE};
+
+    // Control line types
     BusInOut      _commsBus;
     DigitalOut    _registerSel;
     DigitalOut    _modeSel;
     DigitalOut    _enable;
-    void writeChar(char, bool);
-//    void writeData(char);
-    void busyCheck(); 
+    
+    // Private member variables
+    int _col;                   // Cursor coloumn
+    int _row;                   // Cursor row
+    int _ADR;                   // Cursor DDRAM address 
     
-    public:
+    // Private member functions
+    void writeChar(int, bool);  // Write character to display
+    void busyCheck();           // Chek if the display is busy
+    void calcDDRAM(int, int);   // Calculate address in DDRAm for row and coloumn
+    
+    virtual int _getc();        // Virtual reading function for character Stream (not needed by user so it is protected)
+    
+public:
+    // Assign deafault pin names if they are not specified when constructor is run
     C_displayMaster(PinName D1 = defaultD1, PinName D2 = defaultD2, PinName D3 = defaultD3, PinName D4 = defaultD4, PinName RS = defaultRS, PinName RW = defaultRW, PinName EN = defaultEN);
-  //  void write(string text);
-//    void clear();
+   
+    void clear();                 // Clear display
+    virtual int _putc(int value); // Virtual writing function for character Stream 
+
 };
 
 #endif
\ No newline at end of file