General purpose character LCD library. I found the TextLCD library had too many constraints and it didn\\\\\\\'t supply acces to all functions in the HD44780 chipset, so i decided to write my own character lcd library.
charLcd.cpp@2:18f6402fd025, 2011-04-07 (annotated)
- Committer:
- lktromp
- Date:
- Thu Apr 07 11:29:55 2011 +0000
- Revision:
- 2:18f6402fd025
- Parent:
- 1:1349bedd5793
Little bit further
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lktromp | 1:1349bedd5793 | 1 | #include "mbed.h" |
lktromp | 1:1349bedd5793 | 2 | #include "charLcd.h" |
lktromp | 1:1349bedd5793 | 3 | #include "hd44780.h" |
lktromp | 1:1349bedd5793 | 4 | #include "main.h" |
lktromp | 1:1349bedd5793 | 5 | Serial pc(USBTX, USBRX); |
lktromp | 1:1349bedd5793 | 6 | #define DEBUG |
lktromp | 1:1349bedd5793 | 7 | |
lktromp | 2:18f6402fd025 | 8 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 9 | * |
lktromp | 2:18f6402fd025 | 10 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 11 | * and here |
lktromp | 2:18f6402fd025 | 12 | * |
lktromp | 2:18f6402fd025 | 13 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 14 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 15 | */ |
lktromp | 2:18f6402fd025 | 16 | //constructor for 4-bit lcd control |
lktromp | 1:1349bedd5793 | 17 | charLcd::charLcd(PinName rs, PinName en, PinName rw, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type) |
lktromp | 1:1349bedd5793 | 18 | : cl_rs(rs), cl_rw(rw), cl_en(en), cl_charLcdData(d7, d6, d5, d4) { |
lktromp | 1:1349bedd5793 | 19 | pc.baud(115200); |
lktromp | 1:1349bedd5793 | 20 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 21 | pc.printf("LCD 4bit init\r\n"); |
lktromp | 1:1349bedd5793 | 22 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 23 | charLcdResetLCD(); |
lktromp | 1:1349bedd5793 | 24 | } |
lktromp | 1:1349bedd5793 | 25 | |
lktromp | 2:18f6402fd025 | 26 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 27 | * |
lktromp | 2:18f6402fd025 | 28 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 29 | * and here |
lktromp | 2:18f6402fd025 | 30 | * |
lktromp | 2:18f6402fd025 | 31 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 32 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 33 | */ |
lktromp | 2:18f6402fd025 | 34 | //constructor for 8-bit lcd control |
lktromp | 1:1349bedd5793 | 35 | charLcd::charLcd(PinName rs, PinName en, PinName rw, PinName d0, PinName d1, PinName d2, PinName d3, PinName d4, PinName d5, |
lktromp | 1:1349bedd5793 | 36 | PinName d6, PinName d7, LCDType type) |
lktromp | 1:1349bedd5793 | 37 | : cl_rs(rs), cl_rw(rw), cl_en(en), cl_charLcdData(d7, d6, d5, d4, d3, d2, d1, d0) { |
lktromp | 1:1349bedd5793 | 38 | |
lktromp | 1:1349bedd5793 | 39 | pc.baud(115200); |
lktromp | 1:1349bedd5793 | 40 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 41 | pc.printf("LCD 8-bit init\r\n"); |
lktromp | 1:1349bedd5793 | 42 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 43 | charLcdResetLCD(); |
lktromp | 1:1349bedd5793 | 44 | |
lktromp | 1:1349bedd5793 | 45 | } |
lktromp | 1:1349bedd5793 | 46 | |
lktromp | 1:1349bedd5793 | 47 | |
lktromp | 2:18f6402fd025 | 48 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 49 | * |
lktromp | 2:18f6402fd025 | 50 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 51 | * and here |
lktromp | 2:18f6402fd025 | 52 | * |
lktromp | 2:18f6402fd025 | 53 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 54 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 55 | */ |
lktromp | 1:1349bedd5793 | 56 | void charLcd::charLcdResetLCD(void) { |
lktromp | 2:18f6402fd025 | 57 | cl_charLcdData.output(); |
lktromp | 2:18f6402fd025 | 58 | cl_charLcdData = 0x00; |
lktromp | 1:1349bedd5793 | 59 | cl_en = 1; |
lktromp | 1:1349bedd5793 | 60 | cl_rs = 0; // command mode |
lktromp | 1:1349bedd5793 | 61 | cl_rw = 0; |
lktromp | 2:18f6402fd025 | 62 | wait_ms(10); // Wait 15ms to ensure powered up |
lktromp | 2:18f6402fd025 | 63 | //charLcdFunctionSet(0,1,0); |
lktromp | 2:18f6402fd025 | 64 | //wait_ms(5); // Wait 15ms to ensure powered up |
lktromp | 2:18f6402fd025 | 65 | //charLcdFunctionSet(0,1,0); |
lktromp | 2:18f6402fd025 | 66 | //wait_us(100); // Wait 15ms to ensure powered up |
lktromp | 2:18f6402fd025 | 67 | //charLcdFunctionSet(0,1,0); |
lktromp | 2:18f6402fd025 | 68 | //wait_us(100); // Wait 15ms to ensure powered up |
lktromp | 2:18f6402fd025 | 69 | //charLcdFunctionSet(0,1,0); |
lktromp | 2:18f6402fd025 | 70 | //charLcdDisplayOn(0); |
lktromp | 2:18f6402fd025 | 71 | while (1) { |
lktromp | 2:18f6402fd025 | 72 | charLcdClear(); |
lktromp | 2:18f6402fd025 | 73 | wait_ms(500); |
lktromp | 2:18f6402fd025 | 74 | cl_charLcdData = 0x00; |
lktromp | 2:18f6402fd025 | 75 | wait_ms(500); |
lktromp | 2:18f6402fd025 | 76 | } |
lktromp | 2:18f6402fd025 | 77 | charLcdEntryMode(shift_inc); |
lktromp | 2:18f6402fd025 | 78 | wait_ms(20); // Wait 15ms to ensure powered up |
lktromp | 1:1349bedd5793 | 79 | charLcdFunctionSet(0,1,0); |
lktromp | 2:18f6402fd025 | 80 | wait_ms(20); // Wait 15ms to ensure powered up |
lktromp | 1:1349bedd5793 | 81 | charLcdDisplayOn(1); |
lktromp | 1:1349bedd5793 | 82 | wait_ms(20); // Wait 15ms to ensure powered up |
lktromp | 1:1349bedd5793 | 83 | charLcdCursor(1, 1); |
lktromp | 1:1349bedd5793 | 84 | wait_ms(20); // Wait 15ms to ensure powered up |
lktromp | 2:18f6402fd025 | 85 | charLcdEntryMode(shift_inc); |
lktromp | 1:1349bedd5793 | 86 | } |
lktromp | 1:1349bedd5793 | 87 | |
lktromp | 2:18f6402fd025 | 88 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 89 | * |
lktromp | 2:18f6402fd025 | 90 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 91 | * and here |
lktromp | 2:18f6402fd025 | 92 | * |
lktromp | 2:18f6402fd025 | 93 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 94 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 95 | */ |
lktromp | 1:1349bedd5793 | 96 | void charLcd::charLcdClear (void){ |
lktromp | 1:1349bedd5793 | 97 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 98 | pc.printf("LCD Clear\r\n"); |
lktromp | 1:1349bedd5793 | 99 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 100 | charLcdSendCommand(LCD_CLEAR); |
lktromp | 1:1349bedd5793 | 101 | } |
lktromp | 2:18f6402fd025 | 102 | |
lktromp | 2:18f6402fd025 | 103 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 104 | * |
lktromp | 2:18f6402fd025 | 105 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 106 | * and here |
lktromp | 2:18f6402fd025 | 107 | * |
lktromp | 2:18f6402fd025 | 108 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 109 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 110 | */ |
lktromp | 1:1349bedd5793 | 111 | void charLcd::charLcdReturnHome(){ |
lktromp | 1:1349bedd5793 | 112 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 113 | pc.printf("LCD Home\r\n"); |
lktromp | 1:1349bedd5793 | 114 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 115 | charLcdSendCommand(LCD_HOME); |
lktromp | 1:1349bedd5793 | 116 | } |
lktromp | 1:1349bedd5793 | 117 | |
lktromp | 2:18f6402fd025 | 118 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 119 | * |
lktromp | 2:18f6402fd025 | 120 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 121 | * and here |
lktromp | 2:18f6402fd025 | 122 | * |
lktromp | 2:18f6402fd025 | 123 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 124 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 125 | */ |
lktromp | 2:18f6402fd025 | 126 | //void charLcd::charLcdEntryMode(uint8 increment, uint8 shift){ |
lktromp | 2:18f6402fd025 | 127 | void charLcd::charLcdEntryMode(t_charlcd_entry_mode entrymode) { |
lktromp | 1:1349bedd5793 | 128 | uint8 cmd = LCD_ENTRY_MODE; |
lktromp | 2:18f6402fd025 | 129 | |
lktromp | 2:18f6402fd025 | 130 | switch(entrymode) { |
lktromp | 2:18f6402fd025 | 131 | case shift_inc: {cmd |= (LCD_ENTRY_SHIFT | LCD_ENTRY_INC); break;}; |
lktromp | 2:18f6402fd025 | 132 | case shift_dec: {cmd |= (LCD_ENTRY_SHIFT | LCD_ENTRY_DEC );break;}; |
lktromp | 2:18f6402fd025 | 133 | case noshift_inc: {cmd |= (LCD_ENTRY_STAT | LCD_ENTRY_INC); break;}; |
lktromp | 2:18f6402fd025 | 134 | case noshift_dec: {cmd |= (LCD_ENTRY_STAT | LCD_ENTRY_DEC); break;}; |
lktromp | 2:18f6402fd025 | 135 | } |
lktromp | 2:18f6402fd025 | 136 | /* |
lktromp | 1:1349bedd5793 | 137 | if (increment == 0x00){ |
lktromp | 1:1349bedd5793 | 138 | cmd |= LCD_ENTRY_DEC; |
lktromp | 1:1349bedd5793 | 139 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 140 | pc.printf("LCD Entry Mode decrement\r\n"); |
lktromp | 1:1349bedd5793 | 141 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 142 | } else { |
lktromp | 1:1349bedd5793 | 143 | cmd |= LCD_ENTRY_INC; |
lktromp | 1:1349bedd5793 | 144 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 145 | pc.printf("LCD Entry Mode Increment\r\n"); |
lktromp | 1:1349bedd5793 | 146 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 147 | } |
lktromp | 1:1349bedd5793 | 148 | if (shift == 0x00){ |
lktromp | 2:18f6402fd025 | 149 | cmd |= LCD_ENTRY_STAT; |
lktromp | 1:1349bedd5793 | 150 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 151 | pc.printf("LCD Entry Mode Static\r\n"); |
lktromp | 2:18f6402fd025 | 152 | #endif //DEBUG |
lktromp | 2:18f6402fd025 | 153 | |
lktromp | 1:1349bedd5793 | 154 | |
lktromp | 1:1349bedd5793 | 155 | } else { |
lktromp | 1:1349bedd5793 | 156 | cmd |=LCD_ENTRY_SHIFT; |
lktromp | 1:1349bedd5793 | 157 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 158 | pc.printf("LCD Entry Mode Shift\r\n"); |
lktromp | 1:1349bedd5793 | 159 | #endif //DEBUG |
lktromp | 2:18f6402fd025 | 160 | } */ |
lktromp | 1:1349bedd5793 | 161 | charLcdSendCommand(cmd); |
lktromp | 1:1349bedd5793 | 162 | |
lktromp | 1:1349bedd5793 | 163 | } |
lktromp | 1:1349bedd5793 | 164 | |
lktromp | 2:18f6402fd025 | 165 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 166 | * |
lktromp | 2:18f6402fd025 | 167 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 168 | * and here |
lktromp | 2:18f6402fd025 | 169 | * |
lktromp | 2:18f6402fd025 | 170 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 171 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 172 | */ |
lktromp | 1:1349bedd5793 | 173 | void charLcd::charLcdDisplayOn(uint8 on){ |
lktromp | 1:1349bedd5793 | 174 | uint8 cmd = LCD_DISPLAY_CTR; |
lktromp | 1:1349bedd5793 | 175 | if (on == 0x00){ |
lktromp | 1:1349bedd5793 | 176 | cmd |= LCD_DISP_OFF; |
lktromp | 1:1349bedd5793 | 177 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 178 | pc.printf("LCD Display Control Display off\r\n"); |
lktromp | 1:1349bedd5793 | 179 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 180 | } else { |
lktromp | 1:1349bedd5793 | 181 | cmd |= LCD_DISP_ON; |
lktromp | 1:1349bedd5793 | 182 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 183 | pc.printf("LCD Display Control Display on\r\n"); |
lktromp | 1:1349bedd5793 | 184 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 185 | } |
lktromp | 1:1349bedd5793 | 186 | charLcdSendCommand(cmd); |
lktromp | 1:1349bedd5793 | 187 | } |
lktromp | 1:1349bedd5793 | 188 | |
lktromp | 2:18f6402fd025 | 189 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 190 | * |
lktromp | 2:18f6402fd025 | 191 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 192 | * and here |
lktromp | 2:18f6402fd025 | 193 | * |
lktromp | 2:18f6402fd025 | 194 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 195 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 196 | */ |
lktromp | 1:1349bedd5793 | 197 | void charLcd::charLcdCursor(uint8 cursor, uint8 blink){ |
lktromp | 1:1349bedd5793 | 198 | uint8 cmd = LCD_DISPLAY_CTR; |
lktromp | 1:1349bedd5793 | 199 | if (cursor == 0x00){ |
lktromp | 1:1349bedd5793 | 200 | cmd |= LCD_CURSOR_OFF; |
lktromp | 1:1349bedd5793 | 201 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 202 | pc.printf("LCD Display Control Cursor off\r\n"); |
lktromp | 1:1349bedd5793 | 203 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 204 | } else { |
lktromp | 1:1349bedd5793 | 205 | cmd |= LCD_CURSOR_ON; |
lktromp | 1:1349bedd5793 | 206 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 207 | pc.printf("LCD Display Control Cursor on\r\n"); |
lktromp | 1:1349bedd5793 | 208 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 209 | } |
lktromp | 1:1349bedd5793 | 210 | if (blink == 0x00){ |
lktromp | 1:1349bedd5793 | 211 | cmd |= LCD_BLINK_OFF; |
lktromp | 1:1349bedd5793 | 212 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 213 | pc.printf("LCD Display Control Cursor Blink off\r\n"); |
lktromp | 1:1349bedd5793 | 214 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 215 | } else { |
lktromp | 1:1349bedd5793 | 216 | cmd |=LCD_BLINK_ON; |
lktromp | 1:1349bedd5793 | 217 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 218 | pc.printf("LCD Display Control Cursor Blink on\r\n"); |
lktromp | 1:1349bedd5793 | 219 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 220 | } |
lktromp | 1:1349bedd5793 | 221 | charLcdSendCommand(cmd); |
lktromp | 1:1349bedd5793 | 222 | } |
lktromp | 1:1349bedd5793 | 223 | |
lktromp | 2:18f6402fd025 | 224 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 225 | * |
lktromp | 2:18f6402fd025 | 226 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 227 | * and here |
lktromp | 2:18f6402fd025 | 228 | * |
lktromp | 2:18f6402fd025 | 229 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 230 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 231 | */ |
lktromp | 1:1349bedd5793 | 232 | void charLcd::charLcdShift(uint8 left, uint8 cursor){ |
lktromp | 1:1349bedd5793 | 233 | uint8 cmd = LCD_SHIFT; |
lktromp | 1:1349bedd5793 | 234 | if (left == 0x00){ |
lktromp | 1:1349bedd5793 | 235 | cmd |= LCD_SHIFT_LEFT; |
lktromp | 1:1349bedd5793 | 236 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 237 | pc.printf("LCD Shift Control Shift Left\r\n"); |
lktromp | 1:1349bedd5793 | 238 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 239 | } else { |
lktromp | 1:1349bedd5793 | 240 | cmd |= LCD_SHIFT_RIGHT; |
lktromp | 1:1349bedd5793 | 241 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 242 | pc.printf("LCD Display Control Shift Right\r\n"); |
lktromp | 1:1349bedd5793 | 243 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 244 | } |
lktromp | 1:1349bedd5793 | 245 | if (cursor == 0x00){ |
lktromp | 1:1349bedd5793 | 246 | cmd |= LCD_SHIFT_DISP; |
lktromp | 1:1349bedd5793 | 247 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 248 | pc.printf("LCD Display Control Shift Display\r\n"); |
lktromp | 1:1349bedd5793 | 249 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 250 | } else { |
lktromp | 1:1349bedd5793 | 251 | cmd |= LCD_SHIFT_CURS; |
lktromp | 1:1349bedd5793 | 252 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 253 | pc.printf("LCD Display Control Shift Cursor\r\n"); |
lktromp | 1:1349bedd5793 | 254 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 255 | } |
lktromp | 1:1349bedd5793 | 256 | charLcdSendCommand(cmd); |
lktromp | 1:1349bedd5793 | 257 | } |
lktromp | 1:1349bedd5793 | 258 | |
lktromp | 2:18f6402fd025 | 259 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 260 | * |
lktromp | 2:18f6402fd025 | 261 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 262 | * and here |
lktromp | 2:18f6402fd025 | 263 | * |
lktromp | 2:18f6402fd025 | 264 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 265 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 266 | */ |
lktromp | 1:1349bedd5793 | 267 | void charLcd::charLcdFunctionSet(uint8 dots, uint8 lines, uint8 bits){ |
lktromp | 1:1349bedd5793 | 268 | uint8 cmd = LCD_FUNCTION; |
lktromp | 1:1349bedd5793 | 269 | if (dots == 0x00){ |
lktromp | 1:1349bedd5793 | 270 | cmd |= LCD_FUNC_5x8; |
lktromp | 1:1349bedd5793 | 271 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 272 | pc.printf("LCD Display Function Control 5x8\r\n"); |
lktromp | 1:1349bedd5793 | 273 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 274 | } else { |
lktromp | 1:1349bedd5793 | 275 | cmd |= LCD_FUNC_5x10; |
lktromp | 1:1349bedd5793 | 276 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 277 | pc.printf("LCD Display Function Control 5x10\r\n"); |
lktromp | 1:1349bedd5793 | 278 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 279 | } |
lktromp | 1:1349bedd5793 | 280 | if (lines == 0x00){ |
lktromp | 1:1349bedd5793 | 281 | cmd |= LCD_FUNC_1LINES; |
lktromp | 1:1349bedd5793 | 282 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 283 | pc.printf("LCD Display Function Control 1 Line\r\n"); |
lktromp | 1:1349bedd5793 | 284 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 285 | } else { |
lktromp | 1:1349bedd5793 | 286 | cmd |= LCD_FUNC_2LINES; |
lktromp | 1:1349bedd5793 | 287 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 288 | pc.printf("LCD Display Function Control 2 Lines\r\n"); |
lktromp | 1:1349bedd5793 | 289 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 290 | } |
lktromp | 1:1349bedd5793 | 291 | if (bits == 0x00){ |
lktromp | 1:1349bedd5793 | 292 | cmd |= LCD_FUNC_8BIT; |
lktromp | 1:1349bedd5793 | 293 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 294 | pc.printf("LCD Display Function Control 8 BIT\r\n"); |
lktromp | 1:1349bedd5793 | 295 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 296 | } else { |
lktromp | 1:1349bedd5793 | 297 | cmd |= LCD_FUNC_4BIT; |
lktromp | 1:1349bedd5793 | 298 | #ifdef DEBUG |
lktromp | 1:1349bedd5793 | 299 | pc.printf("LCD Display Function Control 4 BIT\r\n"); |
lktromp | 1:1349bedd5793 | 300 | #endif //DEBUG |
lktromp | 1:1349bedd5793 | 301 | } |
lktromp | 1:1349bedd5793 | 302 | charLcdSendCommand(cmd); |
lktromp | 1:1349bedd5793 | 303 | //#define LCD_FUNCTION 0x20 |
lktromp | 1:1349bedd5793 | 304 | //#define LCD_FUNC_5x10 0x04 |
lktromp | 1:1349bedd5793 | 305 | //#define LCD_FUNC_5x8 0x00 |
lktromp | 1:1349bedd5793 | 306 | //#define LCD_FUNC_2LINES 0x08 |
lktromp | 1:1349bedd5793 | 307 | //#define LCD_FUNC_1LINES 0x00 |
lktromp | 1:1349bedd5793 | 308 | //#define LCD_FUNC_8BIT 0x10 |
lktromp | 1:1349bedd5793 | 309 | //#define LCD_FUNC_4BIT 0x00 |
lktromp | 1:1349bedd5793 | 310 | } |
lktromp | 1:1349bedd5793 | 311 | |
lktromp | 2:18f6402fd025 | 312 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 313 | * |
lktromp | 2:18f6402fd025 | 314 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 315 | * and here |
lktromp | 2:18f6402fd025 | 316 | * |
lktromp | 2:18f6402fd025 | 317 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 318 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 319 | */ |
lktromp | 1:1349bedd5793 | 320 | void charLcd::charLcdSetCGRAMaddress(uint8 adr) { |
lktromp | 1:1349bedd5793 | 321 | charLcdSendCommand(LCD_SET_CGRAM & adr); |
lktromp | 1:1349bedd5793 | 322 | } |
lktromp | 1:1349bedd5793 | 323 | |
lktromp | 2:18f6402fd025 | 324 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 325 | * |
lktromp | 2:18f6402fd025 | 326 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 327 | * and here |
lktromp | 2:18f6402fd025 | 328 | * |
lktromp | 2:18f6402fd025 | 329 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 330 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 331 | */ |
lktromp | 1:1349bedd5793 | 332 | void charLcd::charLcdSetDDRAMaddress(uint8 adr) { |
lktromp | 1:1349bedd5793 | 333 | charLcdSendCommand(LCD_SET_DDRAM & adr); |
lktromp | 1:1349bedd5793 | 334 | } |
lktromp | 1:1349bedd5793 | 335 | |
lktromp | 2:18f6402fd025 | 336 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 337 | * |
lktromp | 2:18f6402fd025 | 338 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 339 | * and here |
lktromp | 2:18f6402fd025 | 340 | * |
lktromp | 2:18f6402fd025 | 341 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 342 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 343 | */ |
lktromp | 1:1349bedd5793 | 344 | uint8 charLcd::charLcdReadBusyFlag() { |
lktromp | 1:1349bedd5793 | 345 | return 0x00; |
lktromp | 1:1349bedd5793 | 346 | } |
lktromp | 1:1349bedd5793 | 347 | |
lktromp | 2:18f6402fd025 | 348 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 349 | * |
lktromp | 2:18f6402fd025 | 350 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 351 | * and here |
lktromp | 2:18f6402fd025 | 352 | * |
lktromp | 2:18f6402fd025 | 353 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 354 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 355 | */ |
lktromp | 1:1349bedd5793 | 356 | void charLcd::charLcdWriteData(uint8 dat){ |
lktromp | 1:1349bedd5793 | 357 | cl_rs = 1; |
lktromp | 2:18f6402fd025 | 358 | cl_rw = 1; |
lktromp | 1:1349bedd5793 | 359 | charLcdWriteByte(dat); |
lktromp | 1:1349bedd5793 | 360 | } |
lktromp | 1:1349bedd5793 | 361 | |
lktromp | 2:18f6402fd025 | 362 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 363 | * |
lktromp | 2:18f6402fd025 | 364 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 365 | * and here |
lktromp | 2:18f6402fd025 | 366 | * |
lktromp | 2:18f6402fd025 | 367 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 368 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 369 | */ |
lktromp | 1:1349bedd5793 | 370 | uint8 charLcd::charLcdReadData(){ |
lktromp | 1:1349bedd5793 | 371 | cl_rs = 0; |
lktromp | 2:18f6402fd025 | 372 | cl_rw = 0; |
lktromp | 1:1349bedd5793 | 373 | return 0x00; |
lktromp | 1:1349bedd5793 | 374 | } |
lktromp | 2:18f6402fd025 | 375 | |
lktromp | 2:18f6402fd025 | 376 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 377 | * |
lktromp | 2:18f6402fd025 | 378 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 379 | * and here |
lktromp | 2:18f6402fd025 | 380 | * |
lktromp | 2:18f6402fd025 | 381 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 382 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 383 | */ |
lktromp | 1:1349bedd5793 | 384 | void charLcd::charLcdSendCommand(uint8 cmd) { |
lktromp | 1:1349bedd5793 | 385 | cl_rs = 0; |
lktromp | 2:18f6402fd025 | 386 | cl_rw = 0; |
lktromp | 1:1349bedd5793 | 387 | charLcdWriteByte(cmd); |
lktromp | 1:1349bedd5793 | 388 | } |
lktromp | 1:1349bedd5793 | 389 | |
lktromp | 2:18f6402fd025 | 390 | /** LCD constructor |
lktromp | 2:18f6402fd025 | 391 | * |
lktromp | 2:18f6402fd025 | 392 | * More details about the function goes here |
lktromp | 2:18f6402fd025 | 393 | * and here |
lktromp | 2:18f6402fd025 | 394 | * |
lktromp | 2:18f6402fd025 | 395 | * @param x a variable used by foo |
lktromp | 2:18f6402fd025 | 396 | * @returns something magical done with x |
lktromp | 2:18f6402fd025 | 397 | */ |
lktromp | 1:1349bedd5793 | 398 | void charLcd::charLcdWriteByte(uint8 byte) { |
lktromp | 1:1349bedd5793 | 399 | cl_charLcdData = byte; |
lktromp | 1:1349bedd5793 | 400 | pc.printf("Write %#X to LCD\r\n", byte); |
lktromp | 2:18f6402fd025 | 401 | wait_us(500); // setup time |
lktromp | 1:1349bedd5793 | 402 | cl_en = 0; |
lktromp | 2:18f6402fd025 | 403 | wait_us(500); //hold time |
lktromp | 1:1349bedd5793 | 404 | cl_en = 1; |
lktromp | 1:1349bedd5793 | 405 | } |