Contains necessary classes and functions for ELEC351

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers displayMaster.hpp Source File

displayMaster.hpp

00001 #ifndef displayMaster
00002 #define displayMaster
00003 
00004 #define defaultD1 D7    // Data Bus LSB
00005 #define defaultD2 D6    // |
00006 #define defaultD3 D4    // |
00007 #define defaultD4 D2    // Data Bus MSB
00008 #define defaultRS D9    // Register Select
00009 #define defaultRW D0    // Read/Write Select
00010 #define defaultEN D8    // Enable
00011 
00012 /* Instructions on using the 16x2 LCD panel are found here:
00013 [https://www.8051projects.net/lcd-interfacing/lcd-4-bit.php]                  */
00014 /* N.B. I did the code from scratch since I do not have the code from ELEC230 */
00015 /* N.B. This class contains blocking function so it goes into its own thread  */
00016 
00017 // Custom 16x2 LCD display driver (4 bit mode only). Works via character stream
00018 class C_displayMaster: public Stream 
00019 {
00020 protected:
00021     
00022     // Control line commands
00023     enum REGISTER {INSTRUCTION, DATA};
00024     enum MODE     {WRITE, READ};
00025     enum VALIDATE {DISABLE, ENABLE};
00026 
00027     // Control line types
00028     BusInOut      _commsBus;
00029     DigitalOut    _registerSel;
00030     DigitalOut    _modeSel;
00031     DigitalOut    _enable;
00032     
00033     // Private member variables
00034     int _col;                   // Cursor coloumn
00035     int _row;                   // Cursor row
00036     int _ADR;                   // Cursor DDRAM address 
00037     
00038     // Private member functions
00039     void writeChar(int, bool);  // Write character to display
00040     void busyCheck();           // Chek if the display is busy
00041     void calcDDRAM(int, int);   // Calculate address in DDRAm for row and coloumn
00042     
00043     virtual int _getc();        // Virtual reading function for character Stream (not needed by user so it is protected)
00044     
00045 public:
00046     // Assign deafault pin names if they are not specified when constructor is run
00047     C_displayMaster(PinName D1 = defaultD1, PinName D2 = defaultD2, PinName D3 = defaultD3, PinName D4 = defaultD4, PinName RS = defaultRS, PinName RW = defaultRW, PinName EN = defaultEN);
00048    
00049     void clear();                 // Clear display
00050     virtual int _putc(int value); // Virtual writing function for character Stream 
00051 
00052 };
00053 
00054 #endif