Contains necessary classes and functions for ELEC351

/media/uploads/Luka_Danilovic/elec_315_prototype_assembly.jpg

Committer:
Luka_Danilovic
Date:
Tue Jan 09 15:47:08 2018 +0000
Revision:
7:92b4783af1d2
Parent:
5:becb1545229d
ELEC351 Library; LCD Driver not working due to a bug I could not diagnose. I suspect it is the initialization.

Who changed what in which revision?

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