Yoshiyuki Uehara / Mbed 2 deprecated Maple

Dependencies:   mbed

Committer:
uehara00
Date:
Mon Oct 10 11:45:51 2011 +0000
Revision:
1:aefa1992ce0f
Parent:
0:0be38b583cf7
Child:
3:eec13a411e94
Date/time display to LCD, adjust by buttons, alarm, timer, clock-output control. Just an example of RTC funtions, not for a practical use.

Who changed what in which revision?

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