Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Maple_LCD.cpp@0:0be38b583cf7, 2011-09-25 (annotated)
- Committer:
- uehara00
- Date:
- Sun Sep 25 11:37:21 2011 +0000
- Revision:
- 0:0be38b583cf7
- Child:
- 1:aefa1992ce0f
Preliminary. Alarm functions are not yet implimented.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uehara00 | 0:0be38b583cf7 | 1 | // MAPLE board[MARM01-BASE] |
uehara00 | 0:0be38b583cf7 | 2 | // LCD(TC1602E-25A) driver |
uehara00 | 0:0be38b583cf7 | 3 | // - 4-bit I/O port. |
uehara00 | 0:0be38b583cf7 | 4 | // - "r/w" is fixed to "w". Read instructions do not work. |
uehara00 | 0:0be38b583cf7 | 5 | // |
uehara00 | 0:0be38b583cf7 | 6 | #include "Maple_LCD.h" |
uehara00 | 0:0be38b583cf7 | 7 | #include "Maple.h" |
uehara00 | 0:0be38b583cf7 | 8 | #include "mbed.h" |
uehara00 | 0:0be38b583cf7 | 9 | |
uehara00 | 0:0be38b583cf7 | 10 | // LCD interface |
uehara00 | 0:0be38b583cf7 | 11 | DigitalOut LCD_rs(p25); |
uehara00 | 0:0be38b583cf7 | 12 | DigitalOut LCD_e(p24); |
uehara00 | 0:0be38b583cf7 | 13 | BusInOut LCD_d4_d7(p12, p13, p14, p23); |
uehara00 | 0:0be38b583cf7 | 14 | int LCD_rw; // dummy .. fixed to 0 on MAPLE Board |
uehara00 | 0:0be38b583cf7 | 15 | |
uehara00 | 0:0be38b583cf7 | 16 | // functions for timing |
uehara00 | 0:0be38b583cf7 | 17 | static void LCD_bus_switch_time() { |
uehara00 | 0:0be38b583cf7 | 18 | __nop(); |
uehara00 | 0:0be38b583cf7 | 19 | } |
uehara00 | 0:0be38b583cf7 | 20 | |
uehara00 | 0:0be38b583cf7 | 21 | static void LCD_data_hold_time() { |
uehara00 | 0:0be38b583cf7 | 22 | __nop(); |
uehara00 | 0:0be38b583cf7 | 23 | } |
uehara00 | 0:0be38b583cf7 | 24 | |
uehara00 | 0:0be38b583cf7 | 25 | static void LCD_data_setup_time() { |
uehara00 | 0:0be38b583cf7 | 26 | wait_us(1); |
uehara00 | 0:0be38b583cf7 | 27 | } |
uehara00 | 0:0be38b583cf7 | 28 | |
uehara00 | 0:0be38b583cf7 | 29 | static void LCD_execution_time() { |
uehara00 | 0:0be38b583cf7 | 30 | wait_us(60); |
uehara00 | 0:0be38b583cf7 | 31 | } |
uehara00 | 0:0be38b583cf7 | 32 | |
uehara00 | 0:0be38b583cf7 | 33 | static void LCD_clear_time() { |
uehara00 | 0:0be38b583cf7 | 34 | wait_us(2500); |
uehara00 | 0:0be38b583cf7 | 35 | } |
uehara00 | 0:0be38b583cf7 | 36 | |
uehara00 | 0:0be38b583cf7 | 37 | // rw 1 1 0 0 0 0 0 0 0 1 1 1 1 1 |
uehara00 | 0:0be38b583cf7 | 38 | // data - - - H H H H H - - - - - - |
uehara00 | 0:0be38b583cf7 | 39 | // e 0 0 0 1 1 1 1 0 0 0 0 0 0 0 |
uehara00 | 0:0be38b583cf7 | 40 | // --1us-- ---60us--- |
uehara00 | 0:0be38b583cf7 | 41 | static void LCD_write_1(int rs, char w) { |
uehara00 | 0:0be38b583cf7 | 42 | LCD_rs = rs; |
uehara00 | 0:0be38b583cf7 | 43 | LCD_rw = 0; |
uehara00 | 0:0be38b583cf7 | 44 | LCD_bus_switch_time(); |
uehara00 | 0:0be38b583cf7 | 45 | LCD_d4_d7.output(); |
uehara00 | 0:0be38b583cf7 | 46 | |
uehara00 | 0:0be38b583cf7 | 47 | LCD_e = 1; |
uehara00 | 0:0be38b583cf7 | 48 | LCD_d4_d7 = w >> 4; |
uehara00 | 0:0be38b583cf7 | 49 | LCD_data_setup_time(); |
uehara00 | 0:0be38b583cf7 | 50 | LCD_e = 0; |
uehara00 | 0:0be38b583cf7 | 51 | |
uehara00 | 0:0be38b583cf7 | 52 | LCD_d4_d7.input(); |
uehara00 | 0:0be38b583cf7 | 53 | LCD_bus_switch_time(); |
uehara00 | 0:0be38b583cf7 | 54 | LCD_rw = 1; |
uehara00 | 0:0be38b583cf7 | 55 | |
uehara00 | 0:0be38b583cf7 | 56 | LCD_execution_time(); |
uehara00 | 0:0be38b583cf7 | 57 | } |
uehara00 | 0:0be38b583cf7 | 58 | |
uehara00 | 0:0be38b583cf7 | 59 | // rw 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 |
uehara00 | 0:0be38b583cf7 | 60 | // data - - - H H H H H L L L L L - - - - - - |
uehara00 | 0:0be38b583cf7 | 61 | // e 0 0 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 |
uehara00 | 0:0be38b583cf7 | 62 | // --1us-- --1us-- ---60us--- |
uehara00 | 0:0be38b583cf7 | 63 | static void LCD_write_2(int rs, char w) { |
uehara00 | 0:0be38b583cf7 | 64 | LCD_rs = rs; |
uehara00 | 0:0be38b583cf7 | 65 | LCD_rw = 0; |
uehara00 | 0:0be38b583cf7 | 66 | LCD_bus_switch_time(); |
uehara00 | 0:0be38b583cf7 | 67 | LCD_d4_d7.output(); |
uehara00 | 0:0be38b583cf7 | 68 | |
uehara00 | 0:0be38b583cf7 | 69 | LCD_e = 1; |
uehara00 | 0:0be38b583cf7 | 70 | LCD_d4_d7 = w >> 4; |
uehara00 | 0:0be38b583cf7 | 71 | LCD_data_setup_time(); |
uehara00 | 0:0be38b583cf7 | 72 | LCD_e = 0; |
uehara00 | 0:0be38b583cf7 | 73 | LCD_data_hold_time(); |
uehara00 | 0:0be38b583cf7 | 74 | |
uehara00 | 0:0be38b583cf7 | 75 | LCD_e = 1; |
uehara00 | 0:0be38b583cf7 | 76 | LCD_d4_d7 = w; |
uehara00 | 0:0be38b583cf7 | 77 | LCD_data_setup_time(); |
uehara00 | 0:0be38b583cf7 | 78 | LCD_e = 0; |
uehara00 | 0:0be38b583cf7 | 79 | |
uehara00 | 0:0be38b583cf7 | 80 | LCD_d4_d7.input(); |
uehara00 | 0:0be38b583cf7 | 81 | LCD_bus_switch_time(); |
uehara00 | 0:0be38b583cf7 | 82 | LCD_rw = 1; |
uehara00 | 0:0be38b583cf7 | 83 | |
uehara00 | 0:0be38b583cf7 | 84 | LCD_execution_time(); |
uehara00 | 0:0be38b583cf7 | 85 | } |
uehara00 | 0:0be38b583cf7 | 86 | |
uehara00 | 0:0be38b583cf7 | 87 | // rw 1 1 1 1 1 1 1 1 1 1 1 1 1 |
uehara00 | 0:0be38b583cf7 | 88 | // data - - - H H H H - L L L L - |
uehara00 | 0:0be38b583cf7 | 89 | // e 0 0 1 1 1 1 0 1 1 1 1 0 0 |
uehara00 | 0:0be38b583cf7 | 90 | // setup setup |
uehara00 | 0:0be38b583cf7 | 91 | static unsigned char LCD_read_2(int rs) { |
uehara00 | 0:0be38b583cf7 | 92 | char r; |
uehara00 | 0:0be38b583cf7 | 93 | |
uehara00 | 0:0be38b583cf7 | 94 | LCD_rs = rs; |
uehara00 | 0:0be38b583cf7 | 95 | LCD_e = 1; |
uehara00 | 0:0be38b583cf7 | 96 | LCD_data_setup_time(); |
uehara00 | 0:0be38b583cf7 | 97 | r = LCD_d4_d7 << 4; |
uehara00 | 0:0be38b583cf7 | 98 | LCD_e = 0; |
uehara00 | 0:0be38b583cf7 | 99 | LCD_data_hold_time(); |
uehara00 | 0:0be38b583cf7 | 100 | |
uehara00 | 0:0be38b583cf7 | 101 | LCD_e = 1; |
uehara00 | 0:0be38b583cf7 | 102 | LCD_data_setup_time(); |
uehara00 | 0:0be38b583cf7 | 103 | r += LCD_d4_d7; |
uehara00 | 0:0be38b583cf7 | 104 | LCD_e = 0; |
uehara00 | 0:0be38b583cf7 | 105 | LCD_data_hold_time(); |
uehara00 | 0:0be38b583cf7 | 106 | |
uehara00 | 0:0be38b583cf7 | 107 | return r; |
uehara00 | 0:0be38b583cf7 | 108 | } |
uehara00 | 0:0be38b583cf7 | 109 | |
uehara00 | 0:0be38b583cf7 | 110 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 111 | // 0 0 : 0 0 0 0 0 0 0 1 :0x01 |
uehara00 | 0:0be38b583cf7 | 112 | void LCD_clear_display() { |
uehara00 | 0:0be38b583cf7 | 113 | LCD_write_2(0, 0x01); |
uehara00 | 0:0be38b583cf7 | 114 | LCD_clear_time(); |
uehara00 | 0:0be38b583cf7 | 115 | } |
uehara00 | 0:0be38b583cf7 | 116 | |
uehara00 | 0:0be38b583cf7 | 117 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 118 | // 0 0 : 0 0 0 0 0 0 1 - :0x02 |
uehara00 | 0:0be38b583cf7 | 119 | void LCD_return_home() { |
uehara00 | 0:0be38b583cf7 | 120 | LCD_write_2(0, 0x02); |
uehara00 | 0:0be38b583cf7 | 121 | LCD_clear_time(); |
uehara00 | 0:0be38b583cf7 | 122 | } |
uehara00 | 0:0be38b583cf7 | 123 | |
uehara00 | 0:0be38b583cf7 | 124 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 125 | // 0 0 : 0 0 0 0 0 1 id s :0x04 |
uehara00 | 0:0be38b583cf7 | 126 | // id: curdor move direction.. 0: decrement, 1: increment |
uehara00 | 0:0be38b583cf7 | 127 | // s: accompanies display shift.. 0: no, 1: yes |
uehara00 | 0:0be38b583cf7 | 128 | void LCD_entry_mode_set(int id, int s) { |
uehara00 | 0:0be38b583cf7 | 129 | char w; |
uehara00 | 0:0be38b583cf7 | 130 | |
uehara00 | 0:0be38b583cf7 | 131 | w = 0x04; |
uehara00 | 0:0be38b583cf7 | 132 | if(id != 0){ w += 0x02; } |
uehara00 | 0:0be38b583cf7 | 133 | if(s != 0){ w += 0x01; } |
uehara00 | 0:0be38b583cf7 | 134 | LCD_write_2(0, w); |
uehara00 | 0:0be38b583cf7 | 135 | } |
uehara00 | 0:0be38b583cf7 | 136 | |
uehara00 | 0:0be38b583cf7 | 137 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 138 | // 0 0 : 0 0 0 0 1 d c b :0x08 |
uehara00 | 0:0be38b583cf7 | 139 | // d: display.. 0: off, 1: on |
uehara00 | 0:0be38b583cf7 | 140 | // c: cursor.. 0: off, 1: on |
uehara00 | 0:0be38b583cf7 | 141 | // b: blinking.. 0: off, 1: on |
uehara00 | 0:0be38b583cf7 | 142 | void LCD_display_on_off_control(int d, int c, int b) { |
uehara00 | 0:0be38b583cf7 | 143 | char w; |
uehara00 | 0:0be38b583cf7 | 144 | |
uehara00 | 0:0be38b583cf7 | 145 | w = 0x08; |
uehara00 | 0:0be38b583cf7 | 146 | if(d != 0){ w += 0x04; } |
uehara00 | 0:0be38b583cf7 | 147 | if(c != 0){ w += 0x02; } |
uehara00 | 0:0be38b583cf7 | 148 | if(b != 0){ w += 0x01; } |
uehara00 | 0:0be38b583cf7 | 149 | LCD_write_2(0, w); |
uehara00 | 0:0be38b583cf7 | 150 | } |
uehara00 | 0:0be38b583cf7 | 151 | |
uehara00 | 0:0be38b583cf7 | 152 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 153 | // 0 0 : 0 0 0 1 sc rl - - :0x10 |
uehara00 | 0:0be38b583cf7 | 154 | // sc: shift/cursor.. 0: cursor move, 1: display shift |
uehara00 | 0:0be38b583cf7 | 155 | // rl: right/left.. 0: shift to the left, 1: shift to the right |
uehara00 | 0:0be38b583cf7 | 156 | void LCD_cursor_or_display_shift(int sc, int rl) { |
uehara00 | 0:0be38b583cf7 | 157 | char w; |
uehara00 | 0:0be38b583cf7 | 158 | |
uehara00 | 0:0be38b583cf7 | 159 | w = 0x10; |
uehara00 | 0:0be38b583cf7 | 160 | if(sc != 0){ w += 0x08; } |
uehara00 | 0:0be38b583cf7 | 161 | if(rl != 0){ w += 0x04; } |
uehara00 | 0:0be38b583cf7 | 162 | LCD_write_2(0, w); |
uehara00 | 0:0be38b583cf7 | 163 | } |
uehara00 | 0:0be38b583cf7 | 164 | |
uehara00 | 0:0be38b583cf7 | 165 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 166 | // 0 0 : 0 0 1 dl n f - - :0x20 |
uehara00 | 0:0be38b583cf7 | 167 | // |
uehara00 | 0:0be38b583cf7 | 168 | // "function set" is used twice at initialization only |
uehara00 | 0:0be38b583cf7 | 169 | // 1st use: 8 bit write |
uehara00 | 0:0be38b583cf7 | 170 | // dl: data length.. 0: 4 bits, 1: 8 bits --> 0 fixed |
uehara00 | 0:0be38b583cf7 | 171 | // |
uehara00 | 0:0be38b583cf7 | 172 | // 2nd use: 4 bit write |
uehara00 | 0:0be38b583cf7 | 173 | // dl = 0 (must not change) |
uehara00 | 0:0be38b583cf7 | 174 | // n: line select.. 0: 1 line, 1: 2 lines |
uehara00 | 0:0be38b583cf7 | 175 | // f: font select.. 0: 5*8 dots, 1: 5*10 dots |
uehara00 | 0:0be38b583cf7 | 176 | void LCD_function_set(int n, int f) { |
uehara00 | 0:0be38b583cf7 | 177 | char w; |
uehara00 | 0:0be38b583cf7 | 178 | |
uehara00 | 0:0be38b583cf7 | 179 | w = 0x20; |
uehara00 | 0:0be38b583cf7 | 180 | if(n != 0){ w += 0x08; } |
uehara00 | 0:0be38b583cf7 | 181 | if(f != 0){ w += 0x04; } |
uehara00 | 0:0be38b583cf7 | 182 | LCD_write_1(0, w); |
uehara00 | 0:0be38b583cf7 | 183 | LCD_write_2(0, w); |
uehara00 | 0:0be38b583cf7 | 184 | } |
uehara00 | 0:0be38b583cf7 | 185 | |
uehara00 | 0:0be38b583cf7 | 186 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 187 | // 0 0 : 0 1 a5 a4 a3 a2 a1 a0:0x40 |
uehara00 | 0:0be38b583cf7 | 188 | // a5-a0: CGRAM address |
uehara00 | 0:0be38b583cf7 | 189 | void LCD_set_CGRAM_address(int a) { |
uehara00 | 0:0be38b583cf7 | 190 | LCD_write_2(0, 0x40 + (a & 0x3f)); |
uehara00 | 0:0be38b583cf7 | 191 | } |
uehara00 | 0:0be38b583cf7 | 192 | |
uehara00 | 0:0be38b583cf7 | 193 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 194 | // 0 0 : 1 a6 a5 a4 a3 a2 a1 a0:0x80 |
uehara00 | 0:0be38b583cf7 | 195 | // a6-a0: DDRAM address |
uehara00 | 0:0be38b583cf7 | 196 | void LCD_set_DDRAM_address(int a) { |
uehara00 | 0:0be38b583cf7 | 197 | LCD_write_2(0, 0x80 + (a & 0x7f)); |
uehara00 | 0:0be38b583cf7 | 198 | } |
uehara00 | 0:0be38b583cf7 | 199 | |
uehara00 | 0:0be38b583cf7 | 200 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 201 | // 0 1 : bf a6 a5 a4 a3 a2 a1 a0 |
uehara00 | 0:0be38b583cf7 | 202 | // bf: busy flag- 0: not busy, 1: busy |
uehara00 | 0:0be38b583cf7 | 203 | // a6-a0: DDRAM address |
uehara00 | 0:0be38b583cf7 | 204 | char LCD_read_busy_flag_and_address() { |
uehara00 | 0:0be38b583cf7 | 205 | return LCD_read_2(0); |
uehara00 | 0:0be38b583cf7 | 206 | } |
uehara00 | 0:0be38b583cf7 | 207 | |
uehara00 | 0:0be38b583cf7 | 208 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 209 | // 1 0 : d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 210 | // d7-d0: DDRAM address |
uehara00 | 0:0be38b583cf7 | 211 | void LCD_write_data_to_CG_or_DDRAM(char d) { |
uehara00 | 0:0be38b583cf7 | 212 | LCD_write_2(1, d); |
uehara00 | 0:0be38b583cf7 | 213 | } |
uehara00 | 0:0be38b583cf7 | 214 | |
uehara00 | 0:0be38b583cf7 | 215 | // rs rw: d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 216 | // 1 1 : d7 d6 d5 d4 d3 d2 d1 d0 |
uehara00 | 0:0be38b583cf7 | 217 | // d7-d0: read data from CGRAM or DDRAM |
uehara00 | 0:0be38b583cf7 | 218 | char LCD_read_data_from_CG_or_DDRAM() { |
uehara00 | 0:0be38b583cf7 | 219 | return LCD_read_2(1); |
uehara00 | 0:0be38b583cf7 | 220 | } |
uehara00 | 0:0be38b583cf7 | 221 | |
uehara00 | 0:0be38b583cf7 | 222 | // an example of CGRAM customizing |
uehara00 | 0:0be38b583cf7 | 223 | void LCD_CGRAM_customize() { |
uehara00 | 0:0be38b583cf7 | 224 | LCD_set_CGRAM_address(0x00); |
uehara00 | 0:0be38b583cf7 | 225 | // 0x00 |
uehara00 | 0:0be38b583cf7 | 226 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 227 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 228 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 229 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 230 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 231 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 232 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 233 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 234 | // 0x01 |
uehara00 | 0:0be38b583cf7 | 235 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 236 | LCD_write_data_to_CG_or_DDRAM(0x11); // 1---1 |
uehara00 | 0:0be38b583cf7 | 237 | LCD_write_data_to_CG_or_DDRAM(0x11); // 1---1 |
uehara00 | 0:0be38b583cf7 | 238 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 239 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 240 | LCD_write_data_to_CG_or_DDRAM(0x1f); // 11111 |
uehara00 | 0:0be38b583cf7 | 241 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 242 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 243 | // 0x02 |
uehara00 | 0:0be38b583cf7 | 244 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 245 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 246 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 247 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 248 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 249 | LCD_write_data_to_CG_or_DDRAM(0x11); // 1---1 |
uehara00 | 0:0be38b583cf7 | 250 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 251 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 252 | // 0x03 |
uehara00 | 0:0be38b583cf7 | 253 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 254 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 255 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 256 | LCD_write_data_to_CG_or_DDRAM(0x11); // 1---1 |
uehara00 | 0:0be38b583cf7 | 257 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 258 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 259 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 260 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 261 | // 0x04 |
uehara00 | 0:0be38b583cf7 | 262 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 263 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 264 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 265 | LCD_write_data_to_CG_or_DDRAM(0x11); // 1---1 |
uehara00 | 0:0be38b583cf7 | 266 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 267 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 268 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 269 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 270 | // 0x05 |
uehara00 | 0:0be38b583cf7 | 271 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 272 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 273 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 274 | LCD_write_data_to_CG_or_DDRAM(0x1f); // 11111 |
uehara00 | 0:0be38b583cf7 | 275 | LCD_write_data_to_CG_or_DDRAM(0x15); // 1-1-1 |
uehara00 | 0:0be38b583cf7 | 276 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 277 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 278 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 279 | // 0x06 |
uehara00 | 0:0be38b583cf7 | 280 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 281 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 282 | LCD_write_data_to_CG_or_DDRAM(0x0a); // -1-1- |
uehara00 | 0:0be38b583cf7 | 283 | LCD_write_data_to_CG_or_DDRAM(0x11); // 1---1 |
uehara00 | 0:0be38b583cf7 | 284 | LCD_write_data_to_CG_or_DDRAM(0x1f); // 11111 |
uehara00 | 0:0be38b583cf7 | 285 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 286 | LCD_write_data_to_CG_or_DDRAM(0x0e); // -111- |
uehara00 | 0:0be38b583cf7 | 287 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 288 | // 0x07 |
uehara00 | 0:0be38b583cf7 | 289 | LCD_write_data_to_CG_or_DDRAM(0x04); // --1-- |
uehara00 | 0:0be38b583cf7 | 290 | LCD_write_data_to_CG_or_DDRAM(0x06); // --11- |
uehara00 | 0:0be38b583cf7 | 291 | LCD_write_data_to_CG_or_DDRAM(0x05); // --1-1 |
uehara00 | 0:0be38b583cf7 | 292 | LCD_write_data_to_CG_or_DDRAM(0x05); // --1-1 |
uehara00 | 0:0be38b583cf7 | 293 | LCD_write_data_to_CG_or_DDRAM(0x0d); // -11-1 |
uehara00 | 0:0be38b583cf7 | 294 | LCD_write_data_to_CG_or_DDRAM(0x1c); // 111-- |
uehara00 | 0:0be38b583cf7 | 295 | LCD_write_data_to_CG_or_DDRAM(0x18); // 11--- |
uehara00 | 0:0be38b583cf7 | 296 | LCD_write_data_to_CG_or_DDRAM(0x00); // ----- |
uehara00 | 0:0be38b583cf7 | 297 | } |
uehara00 | 0:0be38b583cf7 | 298 | |
uehara00 | 0:0be38b583cf7 | 299 | // an example of initializing LCD module .. standard use |
uehara00 | 0:0be38b583cf7 | 300 | void LCD_initialize() { |
uehara00 | 0:0be38b583cf7 | 301 | LCD_function_set(1, 0); // 2 lines, 5*8dots font set |
uehara00 | 0:0be38b583cf7 | 302 | LCD_display_on_off_control(1, 0, 0); // display on, cursor on, blinking on |
uehara00 | 0:0be38b583cf7 | 303 | LCD_entry_mode_set(1, 0); // increment yes, shift no |
uehara00 | 0:0be38b583cf7 | 304 | LCD_CGRAM_customize(); // CGRAM customize by an example above |
uehara00 | 0:0be38b583cf7 | 305 | LCD_clear_display(); // select 1st row and clear display |
uehara00 | 0:0be38b583cf7 | 306 | } |
uehara00 | 0:0be38b583cf7 | 307 | |
uehara00 | 0:0be38b583cf7 | 308 | // print char to LCD module |
uehara00 | 0:0be38b583cf7 | 309 | void LCD_print_char(char c) { |
uehara00 | 0:0be38b583cf7 | 310 | LCD_write_data_to_CG_or_DDRAM(c); |
uehara00 | 0:0be38b583cf7 | 311 | } |
uehara00 | 0:0be38b583cf7 | 312 | |
uehara00 | 0:0be38b583cf7 | 313 | // print string to LCD module |
uehara00 | 0:0be38b583cf7 | 314 | void LCD_print_string(char s[]) { |
uehara00 | 0:0be38b583cf7 | 315 | for(int i = 0; s[i] != '\0'; ++i) { |
uehara00 | 0:0be38b583cf7 | 316 | LCD_write_data_to_CG_or_DDRAM(s[i]); |
uehara00 | 0:0be38b583cf7 | 317 | } |
uehara00 | 0:0be38b583cf7 | 318 | } |
uehara00 | 0:0be38b583cf7 | 319 | |
uehara00 | 0:0be38b583cf7 | 320 | // print char in hex format to LCD module |
uehara00 | 0:0be38b583cf7 | 321 | void LCD_print_hex(char c) { |
uehara00 | 0:0be38b583cf7 | 322 | LCD_write_data_to_CG_or_DDRAM(char_to_hex1(c >> 4)); |
uehara00 | 0:0be38b583cf7 | 323 | LCD_write_data_to_CG_or_DDRAM(char_to_hex1(c & 0x0f)); |
uehara00 | 0:0be38b583cf7 | 324 | } |
uehara00 | 0:0be38b583cf7 | 325 | |
uehara00 | 0:0be38b583cf7 | 326 | // locate LCD module |
uehara00 | 0:0be38b583cf7 | 327 | // row = 0 .. 1 |
uehara00 | 0:0be38b583cf7 | 328 | // column = 0 .. 0x3f |
uehara00 | 0:0be38b583cf7 | 329 | void LCD_locate(int row, int column) { |
uehara00 | 0:0be38b583cf7 | 330 | LCD_set_DDRAM_address(row * 0x40 + column); |
uehara00 | 0:0be38b583cf7 | 331 | } |
uehara00 | 0:0be38b583cf7 | 332 | |
uehara00 | 0:0be38b583cf7 | 333 | // set cursor on/off |
uehara00 | 0:0be38b583cf7 | 334 | // c: cursor .. 0: off, 1: on |
uehara00 | 0:0be38b583cf7 | 335 | // blink = off |
uehara00 | 0:0be38b583cf7 | 336 | void LCD_cursor(int c) { |
uehara00 | 0:0be38b583cf7 | 337 | LCD_display_on_off_control(1, c, 0); |
uehara00 | 0:0be38b583cf7 | 338 | } |