MCPcopy Create free account
hub / github.com/SmingHub/Sming / begin

Method begin

Sming/Libraries/LiquidCrystal/LCD.cpp:76–155  ·  view source on GitHub ↗

PUBLIC METHODS --------------------------------------------------------------------------- When the display powers up, it is configured as follows: 1. Display clear 2. Function set: DL = 1; 8-bit interface data N = 0; 1-line display F = 0; 5x8 dot character font 3. Display on/off control: D = 0; Display off C = 0; Cursor off B = 0; Blinking off 4. Entry mode set: I/D = 1; Increment by 1 S = 0; No

Source from the content-addressed store, hash-verified

74// A call to begin() will reinitialize the LCD.
75//
76void LCD::begin(uint8_t cols, uint8_t lines, uint8_t dotsize)
77{
78 if (lines > 1)
79 {
80 _displayfunction |= LCD_2LINE;
81 }
82 _numlines = lines;
83 _cols = cols;
84
85 // for some 1 line displays you can select a 10 pixel high font
86 // ------------------------------------------------------------
87 if ((dotsize != LCD_5x8DOTS) && (lines == 1))
88 {
89 _displayfunction |= LCD_5x10DOTS;
90 }
91
92 // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
93 // according to datasheet, we need at least 40ms after power rises above 2.7V
94 // before sending commands. Arduino can turn on way before 4.5V so we'll wait
95 // 50
96 // ---------------------------------------------------------------------------
97 delay (100); // 100ms delay
98
99 //put the LCD into 4 bit or 8 bit mode
100 // -------------------------------------
101 if (! (_displayfunction & LCD_8BITMODE))
102 {
103 // this is according to the hitachi HD44780 datasheet
104 // figure 24, pg 46
105
106 // we start in 8bit mode, try to set 4 bit mode
107 send(0x03, FOUR_BITS);
108 delayMicroseconds(4500); // wait min 4.1ms
109
110 // second try
111 send ( 0x03, FOUR_BITS );
112 delayMicroseconds(4500); // wait min 4.1ms
113
114 // third go!
115 send( 0x03, FOUR_BITS );
116 delayMicroseconds(150);
117
118 // finally, set to 4-bit interface
119 send ( 0x02, FOUR_BITS );
120 }
121 else
122 {
123 // this is according to the hitachi HD44780 datasheet
124 // page 45 figure 23
125
126 // Send function set command sequence
127 command(LCD_FUNCTIONSET | _displayfunction);
128 delayMicroseconds(4500); // wait more than 4.1ms
129
130 // second try
131 command(LCD_FUNCTIONSET | _displayfunction);
132 delayMicroseconds(150);
133

Callers

nothing calls this directly

Calls 2

delayFunction · 0.85
delayMicrosecondsFunction · 0.85

Tested by

no test coverage detected