@@ -22,19 +22,19 @@ void LCD_I2C::begin(bool beginWire) {
2222 *
2323 */
2424void LCD_I2C::backlight () {
25- _output.Led = 1 ;
25+ _output.led = 1 ;
2626 // Led pin is independent from LCD data and control lines.
27- I2C_Write (0b00000000 | _output.Led << 3 );
27+ I2C_Write (0b00000000 | _output.led << 3 );
2828}
2929
3030/* *
3131 * @brief switch backlight off
3232 *
3333 */
3434void LCD_I2C::backlightOff () {
35- _output.Led = 0 ;
35+ _output.led = 0 ;
3636 // Led pin is independent from LCD data and control lines.
37- I2C_Write (0b00000000 | _output.Led << 3 );
37+ I2C_Write (0b00000000 | _output.led << 3 );
3838}
3939
4040/* *
@@ -74,7 +74,7 @@ void LCD_I2C::leftToRight() {
7474 _output.rs = 0 ;
7575 _output.rw = 0 ;
7676
77- _entryState |= ( 1 << 1 ) ;
77+ _entryState |= HD44780_ENTRY_SHIFTINCREMENT ;
7878
7979 LCD_Write (HD44780_ENTRY_MODE_SET | _entryState);
8080 delayMicroseconds (37 );
@@ -91,7 +91,7 @@ void LCD_I2C::rightToLeft() {
9191 _output.rs = 0 ;
9292 _output.rw = 0 ;
9393
94- _entryState &= ~( 1 << 1 ) ;
94+ _entryState &= ~HD44780_ENTRY_SHIFTINCREMENT ;
9595
9696 LCD_Write (HD44780_ENTRY_MODE_SET | _entryState);
9797 delayMicroseconds (37 );
@@ -110,7 +110,7 @@ void LCD_I2C::autoscroll() {
110110 _output.rs = 0 ;
111111 _output.rw = 0 ;
112112
113- _entryState |= 1 ;
113+ _entryState |= HD44780_ACCOMPANIES_DISPLAY_SHIFT ;
114114
115115 LCD_Write (HD44780_ENTRY_MODE_SET | _entryState);
116116 delayMicroseconds (37 );
@@ -126,7 +126,7 @@ void LCD_I2C::autoscrollOff() {
126126 _output.rs = 0 ;
127127 _output.rw = 0 ;
128128
129- _entryState &= ~1 ;
129+ _entryState &= ~HD44780_ACCOMPANIES_DISPLAY_SHIFT ;
130130
131131 LCD_Write (HD44780_ENTRY_MODE_SET | _entryState);
132132 delayMicroseconds (37 );
@@ -142,7 +142,7 @@ void LCD_I2C::display() {
142142 _output.rs = 0 ;
143143 _output.rw = 0 ;
144144
145- _displayState |= ( 1 << 2 ) ;
145+ _displayState |= HD44780_DISPLAY_ON ;
146146
147147 LCD_Write (HD44780_DISPLAY_CONTROL | _displayState);
148148 delayMicroseconds (37 );
@@ -157,7 +157,7 @@ void LCD_I2C::displayOff() {
157157 _output.rs = 0 ;
158158 _output.rw = 0 ;
159159
160- _displayState &= ~( 1 << 2 ) ;
160+ _displayState &= ~HD44780_DISPLAY_ON ;
161161
162162 LCD_Write (HD44780_DISPLAY_CONTROL | _displayState);
163163 delayMicroseconds (37 );
@@ -172,7 +172,7 @@ void LCD_I2C::cursor() {
172172 _output.rs = 0 ;
173173 _output.rw = 0 ;
174174
175- _displayState |= ( 1 << 1 ) ;
175+ _displayState |= HD44780_CURSOR_ON ;
176176
177177 LCD_Write (HD44780_DISPLAY_CONTROL | _displayState);
178178 delayMicroseconds (37 );
@@ -187,7 +187,7 @@ void LCD_I2C::cursorOff() {
187187 _output.rs = 0 ;
188188 _output.rw = 0 ;
189189
190- _displayState &= ~( 1 << 1 ) ;
190+ _displayState &= ~HD44780_CURSOR_ON ;
191191
192192 LCD_Write (HD44780_DISPLAY_CONTROL | _displayState);
193193 delayMicroseconds (37 );
@@ -203,7 +203,7 @@ void LCD_I2C::blink() {
203203 _output.rs = 0 ;
204204 _output.rw = 0 ;
205205
206- _displayState |= 1 ;
206+ _displayState |= HD44780_BLINK_ON ;
207207
208208 LCD_Write (HD44780_DISPLAY_CONTROL | _displayState);
209209 delayMicroseconds (37 );
@@ -218,7 +218,7 @@ void LCD_I2C::blinkOff() {
218218 _output.rs = 0 ;
219219 _output.rw = 0 ;
220220
221- _displayState &= ~1 ;
221+ _displayState &= ~HD44780_BLINK_ON ;
222222
223223 LCD_Write (HD44780_DISPLAY_CONTROL | _displayState);
224224 delayMicroseconds (37 );
@@ -327,28 +327,43 @@ void LCD_I2C::InitializeLCD() {
327327 // wait more than 40 ms after Vcc = 2.7 V
328328 delay (50 );
329329
330- // first
330+ // first - 0x30
331331 LCD_Write (0b00110000 , true );
332332 delayMicroseconds (4200 );
333- // second
333+ // second - 0x30
334334 LCD_Write (0b00110000 , true );
335335 delayMicroseconds (150 );
336- // third
336+ // third - 0x30
337337 LCD_Write (0b00110000 , true );
338338 delayMicroseconds (37 );
339339
340- // Function Set - 4 bits mode
340+ // Function Set - 4 bits mode write 0x20
341341 LCD_Write (0b00100000 , true );
342342 delayMicroseconds (37 );
343- // Function Set - 4 bit Interface, 1 = 2 lines, 0 = 5x8 font
344- LCD_Write (0b00101000 );
343+
344+ // Setup Display Function Set - 4 bit Interface, 1 = 2 lines, 0 = 5x8 font
345+ LCD_Write (HD44780_FUNCTION_SET | HD44780_4_BIT_MODE | HD44780_2_LINE | HD44780_5x8_DOTS);
345346 delayMicroseconds (37 );
346347
347348 displayOff ();
348349 clear ();
349350 leftToRight ();
350351}
351352
353+ /* *
354+ * @brief write character code from corresponding code table
355+ *
356+ * see HD44780.pdf => page 17
357+ *
358+ * @param output
359+ */
360+ void LCD_I2C::writeCharCode (uint8_t code) {
361+ _output.rs = 1 ;
362+ LCD_Write (code);
363+ delayMicroseconds (37 );
364+ }
365+
366+
352367/* *
353368 * @brief I²C write function
354369 *
@@ -369,25 +384,25 @@ void LCD_I2C::I2C_Write(uint8_t output) {
369384void LCD_I2C::LCD_Write (uint8_t output, bool initialization) {
370385 _output.data = output;
371386
372- _output.E = true ;
387+ _output.en = true ;
373388 I2C_Write (_output.GetHighData ());
374389 // High part of enable should be > 450 ns
375390 delayMicroseconds (1 );
376391
377- _output.E = false ;
392+ _output.en = false ;
378393 I2C_Write (_output.GetHighData ());
379394
380395 // During initialization we only send half a byte
381396 if (!initialization) {
382397 // I think we need a delay between half byte writes, but no sure how long it needs to be.
383398 delayMicroseconds (37 );
384399
385- _output.E = true ;
400+ _output.en = true ;
386401 I2C_Write (_output.GetLowData ());
387402 // High part of enable should be > 450 ns
388403 delayMicroseconds (1 );
389404
390- _output.E = false ;
405+ _output.en = false ;
391406 I2C_Write (_output.GetLowData ());
392407 }
393408}
0 commit comments