Contains necessary classes and functions for ELEC351
displayMaster/displayMaster.cpp@3:e84fa53173e6, 2017-12-28 (annotated)
- Committer:
- Luka_Danilovic
- Date:
- Thu Dec 28 12:14:53 2017 +0000
- Revision:
- 3:e84fa53173e6
- Child:
- 4:d463eafbabed
ELEC315 Library by student 10497267
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Luka_Danilovic | 3:e84fa53173e6 | 1 | #include "mbed.h" |
Luka_Danilovic | 3:e84fa53173e6 | 2 | #include "displayMaster.hpp" |
Luka_Danilovic | 3:e84fa53173e6 | 3 | |
Luka_Danilovic | 3:e84fa53173e6 | 4 | /* Instructions on using the 16x2 LCD panel are found here: |
Luka_Danilovic | 3:e84fa53173e6 | 5 | [https://www.8051projects.net/lcd-interfacing/lcd-4-bit.php] */ |
Luka_Danilovic | 3:e84fa53173e6 | 6 | |
Luka_Danilovic | 3:e84fa53173e6 | 7 | /* N.B. This class contains blocking function */ |
Luka_Danilovic | 3:e84fa53173e6 | 8 | |
Luka_Danilovic | 3:e84fa53173e6 | 9 | C_displayMaster::C_displayMaster(PinName D1, PinName D2, PinName D3 , PinName D4 , PinName RS , PinName RW, PinName EN) |
Luka_Danilovic | 3:e84fa53173e6 | 10 | : |
Luka_Danilovic | 3:e84fa53173e6 | 11 | _commsBus(D1, D2, D3, D4), |
Luka_Danilovic | 3:e84fa53173e6 | 12 | _registerSel(RS), |
Luka_Danilovic | 3:e84fa53173e6 | 13 | _modeSel(RW), |
Luka_Danilovic | 3:e84fa53173e6 | 14 | _enable(EN) |
Luka_Danilovic | 3:e84fa53173e6 | 15 | { |
Luka_Danilovic | 3:e84fa53173e6 | 16 | _enable = DISABLE; // DISABLE at start |
Luka_Danilovic | 3:e84fa53173e6 | 17 | _commsBus[3].output(); // Reconfigure pin as output (MSB) |
Luka_Danilovic | 3:e84fa53173e6 | 18 | Thread::wait(20); // Powerup time |
Luka_Danilovic | 3:e84fa53173e6 | 19 | _commsBus = 0x03; // Pannel config instruction 1 |
Luka_Danilovic | 3:e84fa53173e6 | 20 | _enable = ENABLE; // Validate instruction |
Luka_Danilovic | 3:e84fa53173e6 | 21 | _enable = DISABLE; |
Luka_Danilovic | 3:e84fa53173e6 | 22 | Thread::wait(15); // Wait since BUSY flag not available yet |
Luka_Danilovic | 3:e84fa53173e6 | 23 | _commsBus = 0x03; // Pannel config instruction 2 |
Luka_Danilovic | 3:e84fa53173e6 | 24 | _enable = ENABLE; // Validate instruction |
Luka_Danilovic | 3:e84fa53173e6 | 25 | _enable = DISABLE; |
Luka_Danilovic | 3:e84fa53173e6 | 26 | Thread::wait(5); // Wait since BUSY flag not available yet |
Luka_Danilovic | 3:e84fa53173e6 | 27 | _commsBus = 0x03; // Pannel config instruction 3 |
Luka_Danilovic | 3:e84fa53173e6 | 28 | _enable = ENABLE; // Validate instruction |
Luka_Danilovic | 3:e84fa53173e6 | 29 | _enable = DISABLE; |
Luka_Danilovic | 3:e84fa53173e6 | 30 | Thread::wait(2); // Wait since BUSY flag not available yet |
Luka_Danilovic | 3:e84fa53173e6 | 31 | _commsBus = 0x02; // Pannel config instruction (4 bit mode) |
Luka_Danilovic | 3:e84fa53173e6 | 32 | _enable = ENABLE; // Validate instruction |
Luka_Danilovic | 3:e84fa53173e6 | 33 | _enable = DISABLE; |
Luka_Danilovic | 3:e84fa53173e6 | 34 | Thread::wait(2); // Wait since BUSY flag not available yet |
Luka_Danilovic | 3:e84fa53173e6 | 35 | writeChar(0x28, INSTRUCTION); // Function Set: 4-bit, 2 Line, 5x7 Dots |
Luka_Danilovic | 3:e84fa53173e6 | 36 | writeChar(0x01, INSTRUCTION); // Clear Display (also clear DDRAM content) |
Luka_Danilovic | 3:e84fa53173e6 | 37 | writeChar(0x0C, INSTRUCTION); // Display = on, Cursor = off |
Luka_Danilovic | 3:e84fa53173e6 | 38 | writeChar(0x06, INSTRUCTION); // Entry Mode (Auto increment) |
Luka_Danilovic | 3:e84fa53173e6 | 39 | |
Luka_Danilovic | 3:e84fa53173e6 | 40 | writeChar(0x23, DATA); |
Luka_Danilovic | 3:e84fa53173e6 | 41 | |
Luka_Danilovic | 3:e84fa53173e6 | 42 | } |
Luka_Danilovic | 3:e84fa53173e6 | 43 | |
Luka_Danilovic | 3:e84fa53173e6 | 44 | void C_displayMaster::busyCheck() |
Luka_Danilovic | 3:e84fa53173e6 | 45 | { |
Luka_Danilovic | 3:e84fa53173e6 | 46 | _enable = DISABLE; // DISABLE at start |
Luka_Danilovic | 3:e84fa53173e6 | 47 | _commsBus[3].input(); // Input to listen for BUSY flag (MSB) |
Luka_Danilovic | 3:e84fa53173e6 | 48 | _registerSel = INSTRUCTION; // Comunicate with INSTRUCTION register |
Luka_Danilovic | 3:e84fa53173e6 | 49 | _modeSel = READ; // READ from register |
Luka_Danilovic | 3:e84fa53173e6 | 50 | _enable = ENABLE; // Listen for BUSY flag |
Luka_Danilovic | 3:e84fa53173e6 | 51 | while(_commsBus[3]) { |
Luka_Danilovic | 3:e84fa53173e6 | 52 | _enable != _enable; // Repeat read while BUSY flag is set |
Luka_Danilovic | 3:e84fa53173e6 | 53 | } |
Luka_Danilovic | 3:e84fa53173e6 | 54 | _enable = DISABLE; // Leave DISABLED upon exit |
Luka_Danilovic | 3:e84fa53173e6 | 55 | _modeSel = WRITE; // Return to WRITE mode |
Luka_Danilovic | 3:e84fa53173e6 | 56 | _commsBus[3].output(); // Reconfigure pin as output (MSB) |
Luka_Danilovic | 3:e84fa53173e6 | 57 | } |
Luka_Danilovic | 3:e84fa53173e6 | 58 | |
Luka_Danilovic | 3:e84fa53173e6 | 59 | void C_displayMaster::writeChar(char instructions, bool REGISTER) |
Luka_Danilovic | 3:e84fa53173e6 | 60 | { |
Luka_Danilovic | 3:e84fa53173e6 | 61 | _enable = DISABLE; // DISABLE at start |
Luka_Danilovic | 3:e84fa53173e6 | 62 | _commsBus[3].output(); // Reconfigure pin as output (MSB) |
Luka_Danilovic | 3:e84fa53173e6 | 63 | _registerSel = REGISTER; // Chose register to comunicate with |
Luka_Danilovic | 3:e84fa53173e6 | 64 | _modeSel = WRITE; // WRITE to register |
Luka_Danilovic | 3:e84fa53173e6 | 65 | _commsBus = (instructions>>4);// Top nibble |
Luka_Danilovic | 3:e84fa53173e6 | 66 | _enable = ENABLE; // validate signal |
Luka_Danilovic | 3:e84fa53173e6 | 67 | busyCheck(); |
Luka_Danilovic | 3:e84fa53173e6 | 68 | _commsBus = (instructions); // Bottom nibble |
Luka_Danilovic | 3:e84fa53173e6 | 69 | _enable = ENABLE; // validate signal |
Luka_Danilovic | 3:e84fa53173e6 | 70 | busyCheck(); |
Luka_Danilovic | 3:e84fa53173e6 | 71 | } |