Baseline for testing
LCD.h@1:0f1dffc6103a, 2019-09-12 (annotated)
- Committer:
- foxbrianr
- Date:
- Thu Sep 12 11:27:29 2019 +0000
- Revision:
- 1:0f1dffc6103a
- Parent:
- 0:c428f1d60316
- Child:
- 2:73721d9e0056
beta1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
foxbrianr | 0:c428f1d60316 | 1 | |
foxbrianr | 0:c428f1d60316 | 2 | #ifndef _LCD_ |
foxbrianr | 0:c428f1d60316 | 3 | #define _LCD_ |
foxbrianr | 0:c428f1d60316 | 4 | |
foxbrianr | 0:c428f1d60316 | 5 | #include "mbed.h" |
foxbrianr | 0:c428f1d60316 | 6 | |
foxbrianr | 0:c428f1d60316 | 7 | /* |
foxbrianr | 0:c428f1d60316 | 8 | * LCD commands. |
foxbrianr | 0:c428f1d60316 | 9 | */ |
foxbrianr | 0:c428f1d60316 | 10 | // Clear display: |
foxbrianr | 0:c428f1d60316 | 11 | #define LCD_CLEAR (1 << 0) |
foxbrianr | 0:c428f1d60316 | 12 | |
foxbrianr | 0:c428f1d60316 | 13 | // return cursor and LCD to home position: |
foxbrianr | 0:c428f1d60316 | 14 | #define LCD_HOME (1 << 1) |
foxbrianr | 0:c428f1d60316 | 15 | |
foxbrianr | 0:c428f1d60316 | 16 | // set cursor move direction: |
foxbrianr | 0:c428f1d60316 | 17 | #define LCD_MOVEDIR (1 << 2) |
foxbrianr | 0:c428f1d60316 | 18 | // shift display when byte written to display |
foxbrianr | 0:c428f1d60316 | 19 | #define LCD_MOVEDIR_SHIFT (1 << 0) |
foxbrianr | 0:c428f1d60316 | 20 | // increment the cursor after each byte written: |
foxbrianr | 0:c428f1d60316 | 21 | #define LCD_MOVEDIR_ID (1 << 1) |
foxbrianr | 0:c428f1d60316 | 22 | |
foxbrianr | 0:c428f1d60316 | 23 | // Enable display/cursor: |
foxbrianr | 0:c428f1d60316 | 24 | #define LCD_DISPEN (1 << 3) |
foxbrianr | 0:c428f1d60316 | 25 | // turn cursor blink on: |
foxbrianr | 0:c428f1d60316 | 26 | #define LCD_DISPEN_BLINK (1 << 0) |
foxbrianr | 0:c428f1d60316 | 27 | // turn cursor on: |
foxbrianr | 0:c428f1d60316 | 28 | #define LCD_DISPEN_CURSOR (1 << 1) |
foxbrianr | 0:c428f1d60316 | 29 | // turn display on: |
foxbrianr | 0:c428f1d60316 | 30 | #define LCD_DISPEN_DISP (1 << 2) |
foxbrianr | 0:c428f1d60316 | 31 | |
foxbrianr | 0:c428f1d60316 | 32 | // move cursor/shift display: |
foxbrianr | 0:c428f1d60316 | 33 | #define LCD_MCSD (1 << 4) |
foxbrianr | 0:c428f1d60316 | 34 | // direction of shift (right if set): |
foxbrianr | 0:c428f1d60316 | 35 | #define LCD_MCSD_RL (1 << 2) |
foxbrianr | 0:c428f1d60316 | 36 | // turn on display shift: |
foxbrianr | 0:c428f1d60316 | 37 | #define LCD_MCSD_SC (1 << 3) |
foxbrianr | 0:c428f1d60316 | 38 | |
foxbrianr | 0:c428f1d60316 | 39 | // set interface length: |
foxbrianr | 0:c428f1d60316 | 40 | #define LCD_SETIFLEN (1 << 5) |
foxbrianr | 0:c428f1d60316 | 41 | // set character font 5x10 (1) or 5x7 (0) |
foxbrianr | 0:c428f1d60316 | 42 | #define LCD_SETIFLEN_F (1 << 2) |
foxbrianr | 0:c428f1d60316 | 43 | // set # of display lines 1 if 0, 2 if 1: |
foxbrianr | 0:c428f1d60316 | 44 | #define LCD_SETIFLEN_N (1 << 3) |
foxbrianr | 0:c428f1d60316 | 45 | // set interface length 8 bits if 1, 4 bits if 0 |
foxbrianr | 0:c428f1d60316 | 46 | #define LCD_SETIFLEN_DL (1 << 4) |
foxbrianr | 0:c428f1d60316 | 47 | |
foxbrianr | 0:c428f1d60316 | 48 | // move cursor into CGRAM: |
foxbrianr | 0:c428f1d60316 | 49 | #define LCD_MOVERAM (1 << 6) |
foxbrianr | 0:c428f1d60316 | 50 | |
foxbrianr | 0:c428f1d60316 | 51 | // Move cursor to display: |
foxbrianr | 0:c428f1d60316 | 52 | #define LCD_MOVEDISPLAY (1 << 7) |
foxbrianr | 0:c428f1d60316 | 53 | #define LCD_DATAREAD 0x00 |
foxbrianr | 0:c428f1d60316 | 54 | #define LCD_DATAWRITE 0xFF |
foxbrianr | 0:c428f1d60316 | 55 | #define LCD_READ 1 |
foxbrianr | 0:c428f1d60316 | 56 | #define LCD_WRITE 0 |
foxbrianr | 0:c428f1d60316 | 57 | #define LCD_HIGH 1 |
foxbrianr | 0:c428f1d60316 | 58 | #define LCD_LOW 0 |
foxbrianr | 0:c428f1d60316 | 59 | |
foxbrianr | 0:c428f1d60316 | 60 | #define LCD_RS_COMMANDREGISTERS 0 |
foxbrianr | 0:c428f1d60316 | 61 | #define LCD_RS_DATAREGISTERS 1 |
foxbrianr | 0:c428f1d60316 | 62 | |
foxbrianr | 0:c428f1d60316 | 63 | #define LCD_wakeUp 0x30 // |
foxbrianr | 0:c428f1d60316 | 64 | #define LCD_functionSet 0x28 // Sets the interface data type to 4 bits, 2 lines, and font size 5x8. 0x28 = 0010 1000 |
foxbrianr | 0:c428f1d60316 | 65 | #define LCD_returnHome 0x02 // Sets the cursor to the beginning of the screen. 0x02 = 0000 0010 |
foxbrianr | 0:c428f1d60316 | 66 | #define LCD_setCursor 0x10 // Sets cursor moving and display shift, and direction without changing DDRAM data. 0x10 = 0001 0000 |
foxbrianr | 0:c428f1d60316 | 67 | #define LCD_setDisplayOn 0x0C // Sets Entire Display on, Display on, Cursor on. 0x0C = 0000 1011 |
foxbrianr | 0:c428f1d60316 | 68 | #define LCD_setDisplayEdit 0x0E // Sets Entire Display on, Display on, Cursor on. 0x0C = 0000 1011 |
foxbrianr | 0:c428f1d60316 | 69 | #define LCD_setDisplayBlink 0x0F// Sets Entire Display on, Display on, Cursor on. 0x0C = 0000 1011 |
foxbrianr | 0:c428f1d60316 | 70 | #define LCD_setDisplayOff 0x08 // Sets Entire Display off, Display on, Cursor on. 0x0C = 0000 1000 |
foxbrianr | 0:c428f1d60316 | 71 | #define LCD_entryModeSet 0x06 // Sets Entry Mode. 0x06 = 0000 0110 |
foxbrianr | 0:c428f1d60316 | 72 | #define LCD_cursorModeSet 0x06 // Sets Entry Mode. 0x06 = 0000 0110 |
foxbrianr | 0:c428f1d60316 | 73 | #define LCD_clearDisplay 0x01 // Resets the whole display to blank |
foxbrianr | 0:c428f1d60316 | 74 | |
foxbrianr | 0:c428f1d60316 | 75 | |
foxbrianr | 0:c428f1d60316 | 76 | |
foxbrianr | 0:c428f1d60316 | 77 | class LCD |
foxbrianr | 0:c428f1d60316 | 78 | { |
foxbrianr | 1:0f1dffc6103a | 79 | public: |
foxbrianr | 1:0f1dffc6103a | 80 | |
foxbrianr | 1:0f1dffc6103a | 81 | LCD(); |
foxbrianr | 0:c428f1d60316 | 82 | |
foxbrianr | 1:0f1dffc6103a | 83 | virtual ~LCD(); |
foxbrianr | 1:0f1dffc6103a | 84 | |
foxbrianr | 1:0f1dffc6103a | 85 | void init(void) ; |
foxbrianr | 1:0f1dffc6103a | 86 | |
foxbrianr | 1:0f1dffc6103a | 87 | void display(char *show); |
foxbrianr | 1:0f1dffc6103a | 88 | |
foxbrianr | 1:0f1dffc6103a | 89 | void cls(); |
foxbrianr | 1:0f1dffc6103a | 90 | |
foxbrianr | 1:0f1dffc6103a | 91 | void locate(int row, int column); |
foxbrianr | 1:0f1dffc6103a | 92 | |
foxbrianr | 1:0f1dffc6103a | 93 | void putc(const char c); |
foxbrianr | 1:0f1dffc6103a | 94 | |
foxbrianr | 1:0f1dffc6103a | 95 | void printf(const char* fmt, ...); |
foxbrianr | 1:0f1dffc6103a | 96 | |
foxbrianr | 1:0f1dffc6103a | 97 | int rows() |
foxbrianr | 1:0f1dffc6103a | 98 | { |
foxbrianr | 1:0f1dffc6103a | 99 | return 4; |
foxbrianr | 1:0f1dffc6103a | 100 | } |
foxbrianr | 1:0f1dffc6103a | 101 | |
foxbrianr | 1:0f1dffc6103a | 102 | int columns() |
foxbrianr | 1:0f1dffc6103a | 103 | { |
foxbrianr | 1:0f1dffc6103a | 104 | return 40; |
foxbrianr | 1:0f1dffc6103a | 105 | } |
foxbrianr | 1:0f1dffc6103a | 106 | |
foxbrianr | 1:0f1dffc6103a | 107 | private: |
foxbrianr | 1:0f1dffc6103a | 108 | void setCursorMode (int mode); |
foxbrianr | 1:0f1dffc6103a | 109 | |
foxbrianr | 1:0f1dffc6103a | 110 | void clear(int e1,int e2); |
foxbrianr | 1:0f1dffc6103a | 111 | |
foxbrianr | 1:0f1dffc6103a | 112 | void writeByte1(int value); |
foxbrianr | 1:0f1dffc6103a | 113 | void writeByte2(int value); |
foxbrianr | 1:0f1dffc6103a | 114 | |
foxbrianr | 1:0f1dffc6103a | 115 | void command1(char i) ; |
foxbrianr | 1:0f1dffc6103a | 116 | void command2(char i) ; |
foxbrianr | 1:0f1dffc6103a | 117 | |
foxbrianr | 1:0f1dffc6103a | 118 | void writedata1(char i) ; |
foxbrianr | 1:0f1dffc6103a | 119 | void writedata2(char i) ; |
foxbrianr | 1:0f1dffc6103a | 120 | |
foxbrianr | 1:0f1dffc6103a | 121 | void nextline1(); |
foxbrianr | 1:0f1dffc6103a | 122 | void nextline2(); |
foxbrianr | 1:0f1dffc6103a | 123 | |
foxbrianr | 1:0f1dffc6103a | 124 | int isBusy(int e1,int e2); |
foxbrianr | 1:0f1dffc6103a | 125 | |
foxbrianr | 1:0f1dffc6103a | 126 | int isBusy1(void); |
foxbrianr | 1:0f1dffc6103a | 127 | int isBusy2(void); |
foxbrianr | 1:0f1dffc6103a | 128 | |
foxbrianr | 1:0f1dffc6103a | 129 | void waitBusy(); |
foxbrianr | 1:0f1dffc6103a | 130 | |
foxbrianr | 1:0f1dffc6103a | 131 | void write(const char* text); |
foxbrianr | 1:0f1dffc6103a | 132 | void writeLine(int line, const char* text ); |
foxbrianr | 1:0f1dffc6103a | 133 | void writeCharacter(const char c, int row, int column); |
foxbrianr | 1:0f1dffc6103a | 134 | void writeCharacters(const char* text, int row, int column); |
foxbrianr | 1:0f1dffc6103a | 135 | |
foxbrianr | 1:0f1dffc6103a | 136 | void writeCommand(char value,int e1,int e2); |
foxbrianr | 1:0f1dffc6103a | 137 | void writeChar (char value,int e1,int e2); |
foxbrianr | 1:0f1dffc6103a | 138 | void writeData (char value,int e1,int e2); |
foxbrianr | 1:0f1dffc6103a | 139 | |
foxbrianr | 1:0f1dffc6103a | 140 | int address(int row, int column); |
foxbrianr | 1:0f1dffc6103a | 141 | |
foxbrianr | 1:0f1dffc6103a | 142 | void character (int row, int column, char c); |
foxbrianr | 1:0f1dffc6103a | 143 | |
foxbrianr | 1:0f1dffc6103a | 144 | DigitalInOut LCD_E1; |
foxbrianr | 1:0f1dffc6103a | 145 | DigitalInOut LCD_E2; |
foxbrianr | 1:0f1dffc6103a | 146 | DigitalInOut LCD_RS; |
foxbrianr | 1:0f1dffc6103a | 147 | DigitalInOut LCD_RW; |
foxbrianr | 1:0f1dffc6103a | 148 | |
foxbrianr | 1:0f1dffc6103a | 149 | BusInOut LCD_DATA; |
foxbrianr | 1:0f1dffc6103a | 150 | |
foxbrianr | 1:0f1dffc6103a | 151 | Mutex mutex; |
foxbrianr | 1:0f1dffc6103a | 152 | |
foxbrianr | 1:0f1dffc6103a | 153 | int _row; |
foxbrianr | 1:0f1dffc6103a | 154 | int _column; |
foxbrianr | 1:0f1dffc6103a | 155 | char isOutput; |
foxbrianr | 0:c428f1d60316 | 156 | |
foxbrianr | 0:c428f1d60316 | 157 | }; |
foxbrianr | 0:c428f1d60316 | 158 | |
foxbrianr | 0:c428f1d60316 | 159 | #endif |