SLS AVR Lib 0.1a
 
Loading...
Searching...
No Matches
dm_hd44780.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------------+
2// This file is part of SLS LCD Library
3// ---------------------------------------------------------------------------+
4// Copyright (C) 2025 Simon Litt <simon@1itt.net> https://coding.1itt.net,
5// https://github.com/SimonLitt
6//
7// This program is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the Free
9// Software Foundation, version 3.
10//
11// This program is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14// more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this program. If not, see <https://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------------+
28#ifndef SLS_LCD_DM_HD44780_H_
29#define SLS_LCD_DM_HD44780_H_
30
31#ifdef SLS_AVR_AVR_H_
32# if !(defined SLS_AVR_LCD_HD44780_PIN_H_)
33# error "Include <sls-avr/lcd_hd44780_pin.h> instead of this file!"
34 //TODO i2c support "Include <sls-avr/lcd_hd44780_pin.h> or <sls-avr/lcd_hd44780_i2c.h> instead of this file!"
35# endif
36#else
37# error "First, enable the target microcontroller header!"
38#endif
39
40// ---------------------------------------------------------------------------+
41// Delays. Default from HD44780 and analogs datasheets. Universal settings.
42// ---------------------------------------------------------------------------+
43
44#ifndef HD44780_WAIT_INIT_MS
46# define HD44780_WAIT_INIT_MS 18
47#endif
48
49#ifndef HD44780_EXEC_TIME_US
50# define HD44780_EXEC_TIME_US 50
51#endif
52
53#ifndef HD44780_LONG_EXEC_TIME_US
54# define HD44780_LONG_EXEC_TIME_US 1760
55#endif
56
57#ifndef HD44780_ENABLE_PULSE_US // 1.5/250000 = 0.6 us
58# define HD44780_ENABLE_PULSE_US 0.8
59#endif
60
61#ifndef HD44780_WAIT_BF_LOOP_US
62# define HD44780_WAIT_BF_LOOP_US 0
63#endif
64
65#ifndef HD44780_INIT_1_MS
66# define HD44780_INIT_1_MS 5
67#endif
68
69#ifndef HD44780_INIT_2_US
70# define HD44780_INIT_2_US 120
71#endif
72
73#ifndef HD44780_INIT_3_US
74# define HD44780_INIT_3_US 50
75#endif
76
77#ifndef HD44780_INIT_4_4_US
78# define HD44780_INIT_4_4_US 50
79#endif
80
81#ifndef HD44780_INIT_OTHER_ADD_US
82# define HD44780_INIT_OTHER_ADD_US 10
83#endif
84
85// ---------------------------------------------------------------------------+
86// Init commands
87// ---------------------------------------------------------------------------+
89#define _HD44780_INIT_8_1_CMD 0b00110000
90#define _HD44780_INIT_8_2_CMD 0b00110000
91#define _HD44780_INIT_8_3_CMD 0b00110000
92
93#define _HD44780_INIT_4_1_CMD 0b00000011
94#define _HD44780_INIT_4_2_CMD 0b00000011
95#define _HD44780_INIT_4_3_CMD 0b00000011
96#define _HD44780_INIT_4_4_CMD 0b00000010
98
99// ---------------------------------------------------------------------------+
100// Clear display instruction
101// ---------------------------------------------------------------------------+
103#define _HD44780_CLEAR 0b00000001
105
106// ---------------------------------------------------------------------------+
107// Return home instruction
108// ---------------------------------------------------------------------------+
110#define _HD44780_HOME 0b00000010
111#define _HD44780_HOME_MASK 0b00000001
112
113#define __HD44780_UNUSED_HOME_0_BIT 0 // Used by some compatible controllers
114#define _HD44780_UNUSED_HOME_0_OFF 0x00
115#define _HD44780_UNUSED_HOME_0_ON (_BV(__HD44780_UNUSED_HOME_0_BIT))
117
118// ---------------------------------------------------------------------------+
119// Entry mode
120// ---------------------------------------------------------------------------+
122#define _HD44780_ENTRY 0b00000100
123#define _HD44780_ENTRY_MASK 0b00000011
124
125#define HD44780_S_BIT 0
126#define HD44780_ID_BIT 1
128
129#define HD44780_S_OFF 0x00
130#define HD44780_S_ON (_BV(HD44780_S_BIT))
131
132#define HD44780_ID_DEC 0x00
133#define HD44780_ID_INC (_BV(HD44780_ID_BIT))
134
135// ---------------------------------------------------------------------------+
136// Display on/off instruction
137// ---------------------------------------------------------------------------+
139#define _HD44780_DISPLAY 0b00001000
140#define _HD44780_DISPLAY_MASK 0b00000111
141
142#define __HD44780_B_BIT 0
143#define __HD44780_C_BIT 1
144#define __HD44780_D_BIT 2
146
147#define HD44780_B_OFF 0x00
148#define HD44780_B_ON (_BV(__HD44780_B_BIT))
149
150#define HD44780_C_OFF 0x00
151#define HD44780_C_ON (_BV(__HD44780_C_BIT))
152
153#define HD44780_D_OFF 0x00
154#define HD44780_D_ON (_BV(__HD44780_D_BIT))
155
156// ---------------------------------------------------------------------------+
157// Cursor / shift
158// ---------------------------------------------------------------------------+
160#define _HD44780_CURSOR 0b00010000
161#define _HD44780_CURSOR_MASK 0b00001111
162
163#define __HD44780_UNUSED_CURSOR_0_BIT 0 // Used by some compatible controllers
164#define __HD44780_UNUSED_CURSOR_1_BIT 1 // Used by some compatible controllers
165#define __HD44780_RL_BIT 2
166#define __HD44780_SCN_BIT 3
167
168#define _HD44780_UNUSED_CURSOR_0_OFF 0x00
169#define _HD44780_UNUSED_CURSOR_0_ON (_BV(__HD44780_UNUSED_CURSOR_0_BIT))
170
171#define _HD44780_UNUSED_CURSOR_1_OFF 0x00
172#define _HD44780_UNUSED_CURSOR_1_ON (_BV(__HD44780_UNUSED_CURSOR_1_BIT))
174
175#define HD44780_RL_LEFT 0x00
176#define HD44780_RL_RIGHT (_BV(__HD44780_RL_BIT))
177
178#define HD44780_SCN_CURS 0x00
179#define HD44780_SCN_DISP (_BV(__HD44780_SCN_BIT))
180
181// ---------------------------------------------------------------------------+
182// Function set instruction
183// ---------------------------------------------------------------------------+
185#define _HD44780_FUNC 0b00100000
186#define _HD44780_FUNC_MASK 0b00011111
187
188#define __HD44780_UNUSED_FUNC_0_BIT 0 // Used by some compatible controllers
189#define __HD44780_UNUSED_FUNC_1_BIT 1 // Used by some compatible controllers
190#define __HD44780_F_BIT 2
191#define __HD44780_N_BIT 3
192#define __HD44780_DL_BIT 4
193
194#define _HD44780_UNUSED_FUNC_0_OFF 0x00
195#define _HD44780_UNUSED_FUNC_0_ON (_BV(__HD44780_UNUSED_FUNC_0_BIT))
196
197#define _HD44780_UNUSED_FUNC_1_OFF 0x00
198#define _HD44780_UNUSED_FUNC_1_ON (_BV(__HD44780_UNUSED_FUNC_1_BIT))
200
201#define HD44780_F_NORMAL 0x00
202#define HD44780_F_BIG (_BV(__HD44780_F_BIT))
203
204#define HD44780_N_1L 0x00
205#define HD44780_N_2L (_BV(__HD44780_N_BIT))
206
207#define HD44780_DL_4BIT 0x00
208#define HD44780_DL_8BIT (_BV(__HD44780_DL_BIT))
209
210
211// ---------------------------------------------------------------------------+
212// CGRAM Address Set
213// ---------------------------------------------------------------------------+
215#define _HD44780_CGRAM 0b01000000
216#define _HD44780_CGRAM_MASK 0b00111111
218
219// ---------------------------------------------------------------------------+
220// Set DDRAM Address Set
221// ---------------------------------------------------------------------------+
223#define _HD44780_DDRAM 0b10000000
224#define _HD44780_DDRAM_MASK 0b01111111
226
228#define __HD44780_ROW_1_DDRAM_ADR 0x00
229#define __HD44780_ROW_2_DDRAM_ADR 0x40
230#define __HD44780_ROW_3_DDRAM_ADR 0x10
231#define __HD44780_ROW_4_DDRAM_ADR 0x50
232
233#define __HD44780_ROW_3_20x4_DDRAM_ADR 0x14
234#define __HD44780_ROW_4_20x4_DDRAM_ADR 0x54
236# ifndef HD44780_ROW_1_DDRAM_ADR
237# define HD44780_ROW_1_DDRAM_ADR __HD44780_ROW_1_DDRAM_ADR
238# endif
239# ifndef HD44780_ROW_2_DDRAM_ADR
240# define HD44780_ROW_2_DDRAM_ADR __HD44780_ROW_2_DDRAM_ADR
241# endif
242# ifndef HD44780_ROW_3_DDRAM_ADR
243# define HD44780_ROW_3_DDRAM_ADR __HD44780_ROW_3_DDRAM_ADR
244# endif
245# ifndef HD44780_ROW_4_DDRAM_ADR
246# define HD44780_ROW_4_DDRAM_ADR __HD44780_ROW_4_DDRAM_ADR
247# endif
248
249# ifndef HD44780_ROW_3_20x4_DDRAM_ADR
250# define HD44780_ROW_3_20x4_DDRAM_ADR __HD44780_ROW_3_20x4_DDRAM_ADR
251# endif
252# ifndef HD44780_ROW_4_20x4_DDRAM_ADR
253# define HD44780_ROW_4_20x4_DDRAM_ADR __HD44780_ROW_4_20x4_DDRAM_ADR
254# endif
255
256// ---------------------------------------------------------------------------+
257// Busy Flag / Address Read
258// ---------------------------------------------------------------------------+
260#define __HD44780_BF_BIT 7
261#define _HD44780_ADDR_MASK 0b01111111
262
264
265// ---------------------------------------------------------------------------+
266#define HD44780_CUSTOM_CHAR_0 0
267#define HD44780_CUSTOM_CHAR_1 1
268#define HD44780_CUSTOM_CHAR_2 2
269#define HD44780_CUSTOM_CHAR_3 3
270#define HD44780_CUSTOM_CHAR_4 4
271#define HD44780_CUSTOM_CHAR_5 5
272#define HD44780_CUSTOM_CHAR_6 6
273#define HD44780_CUSTOM_CHAR_7 7
274
275// ---------------------------------------------------------------------------+
283
284#define HD44780_DISPLAY_8X1 1
285#define HD44780_DISPLAY_16X1 2
286
287#define HD44780_DISPLAY_16X2 12
288#define HD44780_DISPLAY_20X2 13
289#define HD44780_DISPLAY_32X2 14
290#define HD44780_DISPLAY_40X2 15
291
292#define HD44780_DISPLAY_16X4 22
293#define HD44780_DISPLAY_20X4 23
294#define HD44780_DISPLAY_40X4 25
295
308
309#endif // SLS_LCD_DM_HD44780_H_
#define HD44780_DISPLAY_16X1
LCD display 16x1.
Definition dm_hd44780.h:285
#define HD44780_DISPLAY_16X2
LCD display 16x2.
Definition dm_hd44780.h:287
#define HD44780_DISPLAY_20X4
LCD display 20x4.
Definition dm_hd44780.h:293
lcd_line_t
LCD row.
Definition dm_hd44780.h:277
@ LCD_ROW_4
4-th display row
Definition dm_hd44780.h:281
@ LCD_ROW_1
1-st display row
Definition dm_hd44780.h:278
@ LCD_ROW_3
3-rd display row
Definition dm_hd44780.h:280
@ LCD_ROW_2
2-nd display row
Definition dm_hd44780.h:279
#define HD44780_DISPLAY_16X4
LCD display 16x4.
Definition dm_hd44780.h:292
lcd_display_t
LCD display type.
Definition dm_hd44780.h:297
@ LCD_32X2
Resolution 32х2 characters.
Definition dm_hd44780.h:302
@ LCD_20X2
Resolution 20х2 characters.
Definition dm_hd44780.h:301
@ LCD_8X1
Resolution 8х1 characters.
Definition dm_hd44780.h:298
@ LCD_16X2
Resolution 16х2 characters.
Definition dm_hd44780.h:300
@ LCD_16X4
Resolution 16х4 characters.
Definition dm_hd44780.h:304
@ LCD_16X1
Resolution 16х1 characters.
Definition dm_hd44780.h:299
@ LCD_40X2
Resolution 40х2 characters.
Definition dm_hd44780.h:303
@ LCD_20X4
Resolution 20х4 characters.
Definition dm_hd44780.h:305
#define HD44780_DISPLAY_32X2
LCD display 32x2.
Definition dm_hd44780.h:289
#define HD44780_DISPLAY_40X2
LCD display 40x2.
Definition dm_hd44780.h:290
#define HD44780_DISPLAY_20X2
LCD display 20x2.
Definition dm_hd44780.h:288
#define HD44780_DISPLAY_8X1
LCD display 8x1.
Definition dm_hd44780.h:284