Skip to content

Commit 4eb973a

Browse files
author
jenkie
committed
Fixes for 4bit 16x2 LCD
1 parent c2b53f4 commit 4eb973a

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

Arduino_Pedelec_Controller/LiquidCrystalDogm.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en
7373
{
7474
pinMode(_rw_pin, OUTPUT);
7575
}
76+
#if HARDWARE_REV < 20
7677
pinMode(_enable_pin, OUTPUT);
78+
#else
79+
DDRH = DDRH | B00000100;
80+
#endif
7781

7882
if (fourbitmode)
7983
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
@@ -104,7 +108,12 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize)
104108
delayMicroseconds(50000);
105109
// Now we pull both RS and R/W low to begin commands
106110
digitalWrite(_rs_pin, LOW);
111+
#if HARDWARE_REV < 20
107112
digitalWrite(_enable_pin, LOW);
113+
#else
114+
PORTH = PORTH & B11011011;
115+
#endif
116+
108117
if (_rw_pin != 255)
109118
{
110119
digitalWrite(_rw_pin, LOW);
@@ -314,11 +323,23 @@ void LiquidCrystal::send(uint8_t value, uint8_t mode)
314323

315324
void LiquidCrystal::pulseEnable(void)
316325
{
326+
#if HARDWARE_REV < 20
317327
digitalWrite(_enable_pin, LOW);
328+
#else
329+
PORTH = PORTH & B11011011;
330+
#endif
318331
delayMicroseconds(1);
332+
#if HARDWARE_REV < 20
319333
digitalWrite(_enable_pin, HIGH);
334+
#else
335+
PORTH = PORTH | B00000100;
336+
#endif
320337
delayMicroseconds(1); // enable pulse must be >450ns
338+
#if HARDWARE_REV < 20
321339
digitalWrite(_enable_pin, LOW);
340+
#else
341+
PORTH = PORTH & B11011011;
342+
#endif
322343
delayMicroseconds(100); // commands need > 37us to settle
323344
}
324345

@@ -342,4 +363,4 @@ void LiquidCrystal::write8bits(uint8_t value)
342363
}
343364

344365
pulseEnable();
345-
}
366+
}

Arduino_Pedelec_Controller/display.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ static PCD8544 lcd; //for Nokia Display
5252

5353
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
5454
#include "LiquidCrystalDogm.h" //for 4bit (e.g. EA-DOGM) Display
55+
#if HARDWARE_REV < 20
5556
static LiquidCrystal lcd(13, 12, 11, 10, 9, 8); //for 4bit (e.g. EA-DOGM) Display
57+
#else
58+
static LiquidCrystal lcd(6,PH2, 16, 17,7,37); //for 4bit (e.g. EA-DOGM) Display
59+
#endif
5660
#endif
5761

5862
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL)
@@ -119,7 +123,11 @@ static void prepare_important_info(int duration_secs)
119123
#endif
120124

121125
lcd.clear();
126+
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
122127
lcd.setCursor(0, 2);
128+
#elif (DISPLAY_TYPE & DISPLAY_TYPE_16X2)
129+
lcd.setCursor(0, 0);
130+
#endif
123131
}
124132
#endif
125133

@@ -274,7 +282,7 @@ static void display_16x2_setup()
274282
lcd.init();
275283
#endif
276284

277-
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2)
285+
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL)
278286
// Online editor for custom chars (5x8 pixels):
279287
// http://www.quinapalus.com/hd44780udg.html
280288
lcd.createChar(0x01, serial_break_symbol);
@@ -346,7 +354,7 @@ static void display_16x2_view_main()
346354
lcd.setCursor(0,0);
347355
if (spd<10)
348356
{lcd.print(MY_F(" "));}
349-
lcd.print(round(spd),0);
357+
lcd.print(spd,0);
350358
lcd.print(MY_F(" km/h "));
351359

352360
double power_display = power;
@@ -367,15 +375,25 @@ static void display_16x2_view_main()
367375

368376
// Break status
369377
if(brake_stat==0)
378+
#if DISPAY_TYPE==DISPLAY_TYPE_16X2_SERIAL
370379
lcd.write(0x01);
380+
#else
381+
lcd.print(MY_F("B"));
382+
#endif
371383
else if (current_profile) // second profile active?
384+
#if DISPAY_TYPE==DISPLAY_TYPE_16X2_SERIAL
372385
lcd.write(0x03);
386+
#else
387+
lcd.print(MY_F("2"));
388+
#endif
373389
else
374390
lcd.print(MY_F(" "));
375391

376392
lcd.setCursor(0,1);
377393
// Custom battery symbol
394+
#if DISPAY_TYPE==DISPLAY_TYPE_16X2_SERIAL
378395
lcd.write(0x02);
396+
#endif
379397
lcd.print(battery_percent_fromcapacity);
380398
// Note: two extra spaces to clear chars when the capacity gets lower
381399
lcd.print(MY_F("% "));
@@ -1365,4 +1383,4 @@ void display_debug(HardwareSerial* localSerial)
13651383
#endif
13661384

13671385
#endif
1368-
}
1386+
}

0 commit comments

Comments
 (0)