ELEC351 SUBMISSION - Same as on the DLE

/media/uploads/Luka_Danilovic/elec_315_prototype_assembly.jpg

Committer:
Luka_Danilovic
Date:
Wed Jan 10 09:49:43 2018 +0000
Revision:
0:c66224a27cf8
ELEC351 SUBMISSION - SAme as on the DLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Luka_Danilovic 0:c66224a27cf8 1 #ifndef displayMaster
Luka_Danilovic 0:c66224a27cf8 2 #define displayMaster
Luka_Danilovic 0:c66224a27cf8 3
Luka_Danilovic 0:c66224a27cf8 4 #define defaultD1 D7 // Data Bus LSB
Luka_Danilovic 0:c66224a27cf8 5 #define defaultD2 D6 // |
Luka_Danilovic 0:c66224a27cf8 6 #define defaultD3 D4 // |
Luka_Danilovic 0:c66224a27cf8 7 #define defaultD4 D2 // Data Bus MSB
Luka_Danilovic 0:c66224a27cf8 8 #define defaultRS D9 // Register Select
Luka_Danilovic 0:c66224a27cf8 9 #define defaultRW D0 // Read/Write Select
Luka_Danilovic 0:c66224a27cf8 10 #define defaultEN D8 // Enable
Luka_Danilovic 0:c66224a27cf8 11
Luka_Danilovic 0:c66224a27cf8 12 /* Instructions on using the 16x2 LCD panel are found here:
Luka_Danilovic 0:c66224a27cf8 13 [https://www.8051projects.net/lcd-interfacing/lcd-4-bit.php] */
Luka_Danilovic 0:c66224a27cf8 14 /* N.B. I did the code from scratch since I do not have the code from ELEC230 */
Luka_Danilovic 0:c66224a27cf8 15 /* N.B. This class contains blocking function so it goes into its own thread */
Luka_Danilovic 0:c66224a27cf8 16
Luka_Danilovic 0:c66224a27cf8 17 // Custom 16x2 LCD display driver (4 bit mode only). Works via character stream
Luka_Danilovic 0:c66224a27cf8 18 class C_displayMaster: public Stream
Luka_Danilovic 0:c66224a27cf8 19 {
Luka_Danilovic 0:c66224a27cf8 20 protected:
Luka_Danilovic 0:c66224a27cf8 21
Luka_Danilovic 0:c66224a27cf8 22 // Control line commands
Luka_Danilovic 0:c66224a27cf8 23 enum REGISTER {INSTRUCTION, DATA};
Luka_Danilovic 0:c66224a27cf8 24 enum MODE {WRITE, READ};
Luka_Danilovic 0:c66224a27cf8 25 enum VALIDATE {DISABLE, ENABLE};
Luka_Danilovic 0:c66224a27cf8 26
Luka_Danilovic 0:c66224a27cf8 27 // Control line types
Luka_Danilovic 0:c66224a27cf8 28 BusInOut _commsBus;
Luka_Danilovic 0:c66224a27cf8 29 DigitalOut _registerSel;
Luka_Danilovic 0:c66224a27cf8 30 DigitalOut _modeSel;
Luka_Danilovic 0:c66224a27cf8 31 DigitalOut _enable;
Luka_Danilovic 0:c66224a27cf8 32
Luka_Danilovic 0:c66224a27cf8 33 // Private member variables
Luka_Danilovic 0:c66224a27cf8 34 int _col; // Cursor coloumn
Luka_Danilovic 0:c66224a27cf8 35 int _row; // Cursor row
Luka_Danilovic 0:c66224a27cf8 36 int _ADR; // Cursor DDRAM address
Luka_Danilovic 0:c66224a27cf8 37
Luka_Danilovic 0:c66224a27cf8 38 // Private member functions
Luka_Danilovic 0:c66224a27cf8 39 void writeChar(int, bool); // Write character to display
Luka_Danilovic 0:c66224a27cf8 40 void busyCheck(); // Chek if the display is busy
Luka_Danilovic 0:c66224a27cf8 41 void calcDDRAM(int, int); // Calculate address in DDRAm for row and coloumn
Luka_Danilovic 0:c66224a27cf8 42
Luka_Danilovic 0:c66224a27cf8 43 virtual int _getc(); // Virtual reading function for character Stream (not needed by user so it is protected)
Luka_Danilovic 0:c66224a27cf8 44
Luka_Danilovic 0:c66224a27cf8 45 public:
Luka_Danilovic 0:c66224a27cf8 46 // Assign deafault pin names if they are not specified when constructor is run
Luka_Danilovic 0:c66224a27cf8 47 C_displayMaster(PinName D1 = defaultD1, PinName D2 = defaultD2, PinName D3 = defaultD3, PinName D4 = defaultD4, PinName RS = defaultRS, PinName RW = defaultRW, PinName EN = defaultEN);
Luka_Danilovic 0:c66224a27cf8 48
Luka_Danilovic 0:c66224a27cf8 49 void clear(); // Clear display
Luka_Danilovic 0:c66224a27cf8 50 virtual int _putc(int value); // Virtual writing function for character Stream
Luka_Danilovic 0:c66224a27cf8 51
Luka_Danilovic 0:c66224a27cf8 52 };
Luka_Danilovic 0:c66224a27cf8 53
Luka_Danilovic 0:c66224a27cf8 54 #endif