1 | ...
|
2 | void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
3 | if (lines > 1) {
|
4 | _displayfunction |= LCD_2LINE;
|
5 | }
|
6 | _numlines = lines;
|
7 |
|
8 | // for some 1 line displays you can select a 10 pixel high font
|
9 | if ((dotsize != 0) && (lines == 1)) {
|
10 | _displayfunction |= LCD_5x10DOTS;
|
11 | }
|
12 |
|
13 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
|
14 | // according to datasheet, we need at least 40ms after power rises above 2.7V
|
15 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
|
16 | delay(50);
|
17 |
|
18 | // Now we pull both RS and R/W low to begin commands
|
19 | expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1)
|
20 | delay(500);
|
21 |
|
22 | //put the LCD into 4 bit mode
|
23 | // this is according to the hitachi HD44780 datasheet
|
24 | // figure 24, pg 46
|
25 |
|
26 | // Repeat procedures for an 4-Bit Interface OLED(RS0010)
|
27 | for (int rs0010 = 0; rs0010 < 4; rs0010++)
|
28 | {
|
29 | write4bits(0x0 << 9);
|
30 | delayMicroseconds(2000);
|
31 | }
|
32 |
|
33 | // 4-Bit initialization sequence from Technobly
|
34 | write4bits(0x03 << 4); // Put back into 8-bit mode
|
35 | delayMicroseconds(5000);
|
36 |
|
37 | write4bits(0x08 << 4);
|
38 | delayMicroseconds(5000);
|
39 |
|
40 | write4bits(0x02 << 4); // Put into 4-bit mode
|
41 | delayMicroseconds(5000);
|
42 | write4bits(0x02 << 4);
|
43 | delayMicroseconds(5000);
|
44 | write4bits(0x08 << 4);
|
45 | delayMicroseconds(5000);
|
46 |
|
47 | command(0x08); // Turn Off
|
48 | delayMicroseconds(5000);
|
49 |
|
50 | command(0x01); // Clear Display
|
51 | delayMicroseconds(5000);
|
52 |
|
53 | command(0x06); // Set Entry Mode
|
54 | delayMicroseconds(5000);
|
55 |
|
56 | command(0x02); // Home Cursor
|
57 | delayMicroseconds(5000);
|
58 |
|
59 | command(0x0C); // Turn On - enable cursor & blink
|
60 | delayMicroseconds(5000);
|
61 |
|
62 | // set # lines, font size, etc.
|
63 | command(LCD_FUNCTIONSET | _displayfunction);
|
64 | delayMicroseconds(5000);
|
65 |
|
66 | // turn the display on with no cursor or blinking default
|
67 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
|
68 | display();
|
69 | delayMicroseconds(5000);
|
70 |
|
71 | // clear it off
|
72 | clear();
|
73 | delayMicroseconds(5000);
|
74 |
|
75 | // Initialize to default text direction (for roman languages)
|
76 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
|
77 | delayMicroseconds(5000);
|
78 |
|
79 | // set the entry mode
|
80 | command(LCD_ENTRYMODESET | _displaymode);
|
81 | delayMicroseconds(5000);
|
82 |
|
83 | home();
|
84 | delayMicroseconds(5000);
|
85 | }
|
86 | ...
|