Skip to content

Commit 32cfb67

Browse files
authored
Merge pull request #10 from hasenradball/develop
Release v0.3.0
2 parents bf6fafa + a381e16 commit 32cfb67

File tree

10 files changed

+158
-55
lines changed

10 files changed

+158
-55
lines changed

.github/workflows/compile_examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- uses: arduino/compile-sketches@v1
1414
with:
1515
libraries: |

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ This library is licensed under MIT Licence.
6060
# Helpful Links
6161
[Wikipedia - a great description of HD44780 module](https://de.wikipedia.org/wiki/HD44780)
6262

63+
[How to Initialize LCD correctly](https://web.alfredstate.edu/faculty/weimandn/lcd/lcd_initialization/lcd_initialization_index.html)
64+
65+
[LCD Addressing](https://web.alfredstate.edu/faculty/weimandn/lcd/lcd_addressing/lcd_addressing_index.html)
66+

examples/Custom_Chars/Custom_Chars.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ uint8_t snow[8] =
6161
0b10000
6262
};
6363

64-
void setup()
65-
{
64+
void setup() {
6665
lcd.begin();
6766
lcd.display();
6867
lcd.backlight();
@@ -79,6 +78,5 @@ void setup()
7978
lcd.write(3);
8079
}
8180

82-
void loop()
83-
{
81+
void loop() {
8482
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* write_character_codes.ino
3+
*
4+
* Author: Frank Häfele
5+
* Date: 03.05.2024
6+
*
7+
* Object: print characters from code table
8+
*/
9+
10+
#include <LCD-I2C.h>
11+
12+
13+
LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according
14+
15+
void setup() {
16+
// If you are using more I2C devices using the Wire library use lcd.begin(false)
17+
// this stop the library(LCD-I2C) from calling Wire.begin()
18+
lcd.begin();
19+
lcd.display();
20+
lcd.backlight();
21+
}
22+
23+
void loop() {
24+
// write som character code from ROM code A00
25+
lcd.setCursor(0, 1);
26+
lcd.print("print characters");
27+
lcd.setCursor(0, 0);
28+
// writes a H
29+
lcd.writeCharCode(0b01001000);
30+
delay(1000);
31+
32+
// writes a degree sign
33+
lcd.writeCharCode(0b11011111);
34+
delay(1000);
35+
36+
// writes a question mark
37+
lcd.writeCharCode(0b00111111);
38+
delay(1000);
39+
40+
}

keywords.txt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,26 @@ setCursor KEYWORD2
3838
##################################
3939
# Constants (LITERAL1)
4040
##################################
41-
HD44780_CLEAR LITERAL1
42-
HD44780_CLEAR LITERAL1
43-
HD44780_HOME LITERAL1
44-
HD44780_ENTRY_MODE_SET LITERAL1
45-
HD44780_DISPLAY_CONTROL LITERAL1
46-
HD44780_CURSOR_OR_DISPLAY_SHIFT LITERAL1
47-
HD44780_FUNCTION_SET LITERAL1
48-
HD44780_SET_CGRAM_ADDR LITERAL1
49-
HD44780_SET_DDRRAM_ADDR LITERAL1
41+
HD44780_CLEAR_DISPLAY LITERAL1
42+
HD44780_CURSOR_HOME LITERAL1
43+
HD44780_ENTRY_MODE_SET LITERAL1
44+
HD44780_ACCOMPANIES_DISPLAY_SHIFT LITERAL1
45+
HD44780_ENTRY_SHIFTINCREMENT LITERAL1
46+
HD44780_ENTRY_SHIFTDECREMENT LITERAL1
47+
HD44780_DISPLAY_CONTROL LITERAL1
48+
HD44780_BLINK_ON LITERAL1
49+
HD44780_CURSOR_ON LITERAL1
50+
HD44780_DISPLAY_ON LITERAL1
51+
HD44780_CURSOR_OR_DISPLAY_SHIFT LITERAL1
52+
HD44780_SHIFT_RIGHT LITERAL1
53+
HD44780_DISPLAY_SHIFT LITERAL1
54+
HD44780_CURSOR_MOVE LITERAL1
55+
HD44780_FUNCTION_SET LITERAL1
56+
HD44780_5x10_DOTS LITERAL1
57+
HD44780_5x8_DOTS LITERAL1
58+
HD44780_2_LINE LITERAL1
59+
HD44780_1_LINE LITERAL1
60+
HD44780_8_BIT_MODE LITERAL1
61+
HD44780_4_BIT_MODE LITERAL1
62+
HD44780_SET_CGRAM_ADDR LITERAL1
63+
HD44780_SET_DDRRAM_ADDR LITERAL1

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "LCD-I2C",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"repository":
55
{
66
"type": "git",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=LCD-I2C
2-
version=0.2.0
2+
version=0.3.0
33
author=Frank Häfele <mail@frankhaefele.de>
44
maintainer=Frank Häfele <mail@frankhaefele.de>
55
sentence=C++ Library for Liquid Crystal Displays (LCD) with the Hitachi HD44780 display driver.

src/LCD-I2C.cpp

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ void LCD_I2C::begin(bool beginWire) {
2222
*
2323
*/
2424
void 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
*/
3434
void 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) {
369384
void 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
}

src/LCD-I2C.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,32 @@
1010
while the other 4 bits are for the 8 bits of data which are send in parts using the enable output.
1111
*/
1212
struct OutputState {
13+
// Select register
14+
// 0: instruction register
15+
// 1: data register
1316
uint8_t rs = 0;
17+
// select read or write
1418
uint8_t rw = 0;
15-
uint8_t E = 0;
16-
uint8_t Led = 0;
19+
// Enable: starts data read or write
20+
uint8_t en = 0;
21+
// LED status
22+
uint8_t led = 0;
1723
uint8_t data = 0;
1824

1925
uint8_t GetLowData() {
2026
uint8_t buffer = rs;
2127
buffer |= rw << 1;
22-
buffer |= E << 2;
23-
buffer |= Led << 3;
28+
buffer |= en << 2;
29+
buffer |= led << 3;
2430
buffer |= (data & 0x0F) << 4;
25-
2631
return buffer;
2732
}
2833

2934
uint8_t GetHighData() {
3035
uint8_t buffer = rs;
3136
buffer |= rw << 1;
32-
buffer |= E << 2;
33-
buffer |= Led << 3;
37+
buffer |= en << 2;
38+
buffer |= led << 3;
3439
buffer |= (data & 0xF0);
3540
return buffer;
3641
}
@@ -61,6 +66,7 @@ class LCD_I2C : public Print {
6166
void scrollDisplayRight();
6267
void createChar(uint8_t memory_location, uint8_t charmap[]);
6368
void setCursor(uint8_t column, uint8_t row);
69+
void writeCharCode(uint8_t code);
6470
// Method used by the Arduino class "Print" which is the one that provides the .print(string) method
6571
virtual size_t write(uint8_t character);
6672

0 commit comments

Comments
 (0)