mikroSDK Reference Manual
lcd.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2023 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The MikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
44 #ifndef _LCD_H_
45 #define _LCD_H_
46 
47 #ifdef __cplusplus
48 extern "C"{
49 #endif
50 
51 #include "lcd_controllers.h"
52 
56 #define LCD_CMD_FUNCTION_SET ((uint8_t)0x20)
57 #define LCD_CMD_CLEAR ((uint8_t)0x1)
58 #define LCD_CMD_RETURN_HOME ((uint8_t)0x2)
59 #define LCD_CMD_CURSOR_OFF ((uint8_t)0xC)
60 #define LCD_CMD_UNDERLINE_ON ((uint8_t)0xE)
61 #define LCD_CMD_BLINK_CURSOR_ON ((uint8_t)0xF)
62 #define LCD_CMD_MOVE_CURSOR_LEFT ((uint8_t)0x10)
63 #define LCD_CMD_MOVE_CURSOR_RIGHT ((uint8_t)0x14)
64 #define LCD_CMD_TURN_OFF ((uint8_t)0x8)
65 #define LCD_CMD_TURN_ON ((uint8_t)0xC)
66 #define LCD_CMD_SHIFT_LEFT ((uint8_t)0x18)
67 #define LCD_CMD_SHIFT_RIGHT ((uint8_t)0x1C)
68 #define LCD_CMD_MODE_4BIT ((uint8_t)0x08)
69 
74 #define LCD_MAP_PINS(lcd_cfg) LCD_MAP_PINS_4BIT(lcd_cfg)
75 
79 #define LCD_MAP_PINS_4BIT(lcd_cfg) \
80  lcd_cfg.pin_cs = TFT_CS; \
81  lcd_cfg.pin_rst = TFT_RST; \
82  lcd_cfg.pin_backlight = TFT_BPWM; \
83  lcd_cfg.pin_d4 = TFT_D4; \
84  lcd_cfg.pin_d5 = TFT_D5; \
85  lcd_cfg.pin_d6 = TFT_D6; \
86  lcd_cfg.pin_d7 = TFT_D7;
87 
91 #define LCD_MAP_PINS_8BIT(lcd_cfg) \
92  lcd_cfg.pin_cs = TFT_CS; \
93  lcd_cfg.pin_rst = TFT_RST; \
94  lcd_cfg.pin_backlight = TFT_BPWM; \
95  lcd_cfg.pin_d0 = TFT_D0; \
96  lcd_cfg.pin_d1 = TFT_D1; \
97  lcd_cfg.pin_d2 = TFT_D2; \
98  lcd_cfg.pin_d3 = TFT_D3; \
99  lcd_cfg.pin_d4 = TFT_D4; \
100  lcd_cfg.pin_d5 = TFT_D5; \
101  lcd_cfg.pin_d6 = TFT_D6; \
102  lcd_cfg.pin_d7 = TFT_D7;
103 
107 typedef enum
108 {
110  LCD_ERROR = (-1)
111 } lcd_err_t;
112 
116 typedef enum
117 {
120 } lcd_select_t;
121 
125 typedef enum
126 {
129 } lcd_mode_t;
130 
134 typedef enum
135 {
136  LCD_ROW_1 = 0x80,
137  LCD_ROW_2 = 0xC0,
138  LCD_ROW_3 = 0x94,
139  LCD_ROW_4 = 0xD4
140 } lcd_row_t;
141 
145 typedef struct lcd_config
146 {
170  lcd_mode_t mode;
178  uint16_t waitBetweenWrites;
179 } lcd_config_t;
180 
185 typedef void (*init_sequence_ptr)(uint32_t);
186 
190 typedef struct lcd_handle
191 {
209  bool init_state;
211 } lcd_handle_t;
212 
263 void lcd_configure_default( lcd_config_t *config );
264 
293 
321 void lcd_init( lcd_handle_t lcd_handle, init_sequence_ptr init_sequence );
322 
357 void lcd_write( lcd_handle_t lcd_handle, char lcd_cmd_data, lcd_select_t cmd_or_data );
358 
390 void lcd_write_text( lcd_handle_t lcd_handle, char *lcd_data, lcd_row_t row );
391 
427 
463 
496 
525 
554 
584 
614 
644 
674 
704 
736 
765 
794  // middlewaregroup // lcd
797 
798 #ifdef __cplusplus
799 }
800 #endif
801 
802 #endif // _LCD_H_
803 
804 // ------------------------------------------------------------------------ END
lcd_handle::init_sequence
init_sequence_ptr init_sequence
Controller init sequence.
Definition: lcd.h:202
lcd_configure_default
void lcd_configure_default(lcd_config_t *config)
Configure LCD configuration structure.
lcd_handle_t
struct lcd_handle lcd_handle_t
lcd_config::waitBetweenWrites
uint16_t waitBetweenWrites
Time to wait before generating a pulse on CS line.
Definition: lcd.h:177
lcd_cursor_off
void lcd_cursor_off(lcd_handle_t lcd_handle)
Removes cursor.
lcd_config::pin_d0
pin_name_t pin_d0
LCD data pins.
Definition: lcd.h:156
lcd_clear
void lcd_clear(lcd_handle_t lcd_handle)
Clears LCD.
lcd_config::pin_cs
pin_name_t pin_cs
LCD control pins.
Definition: lcd.h:149
LCD_SELECT_CMD
Definition: lcd.h:117
lcd_handle::backlight_pin
digital_out_t backlight_pin
Definition: lcd.h:195
lcd_turn_on
void lcd_turn_on(lcd_handle_t lcd_handle)
Turns LCD ON.
lcd_shift_left
void lcd_shift_left(lcd_handle_t lcd_handle)
Shifts data currently on LCD.
digital_out_t
Digital output driver context structure, consisted of the following fields :
Definition: drv_digital_out.h:71
lcd_write_text
void lcd_write_text(lcd_handle_t lcd_handle, char *lcd_data, lcd_row_t row)
Writes text to LCD.
lcd_row_t
lcd_row_t
Definition: lcd.h:133
lcd_select_t
lcd_select_t
Definition: lcd.h:115
lcd_backlight_on
void lcd_backlight_on(lcd_handle_t lcd_handle)
Turns LCD backlight ON.
lcd_shift_right
void lcd_shift_right(lcd_handle_t lcd_handle)
Shifts data currently on LCD.
lcd_handle::rst_pin
digital_out_t rst_pin
Definition: lcd.h:194
lcd_config::pin_rst
pin_name_t pin_rst
Definition: lcd.h:150
lcd_handle::data_pins
digital_out_t data_pins[8]
Definition: lcd.h:196
lcd_config::pin_d1
pin_name_t pin_d1
Definition: lcd.h:157
lcd_config
Definition: lcd.h:144
lcd_backlight_off
void lcd_backlight_off(lcd_handle_t lcd_handle)
Turns LCD backlight OFF.
LCD_ROW_2
Definition: lcd.h:136
lcd_config_t
struct lcd_config lcd_config_t
lcd_controllers.h
mikroSDK supported LCD controller list.
LCD_ROW_4
Definition: lcd.h:138
LCD_ERROR
Definition: lcd.h:109
lcd_handle::config
lcd_config_t config
Definition: lcd.h:191
lcd_cursor_move_home
void lcd_cursor_move_home(lcd_handle_t lcd_handle)
Moves cursor to first position.
lcd_config::pin_d4
pin_name_t pin_d4
Definition: lcd.h:160
LCD_ROW_1
Definition: lcd.h:135
lcd_config::pin_d3
pin_name_t pin_d3
Definition: lcd.h:159
lcd_handle::cs_pin
digital_out_t cs_pin
Definition: lcd.h:193
lcd_write
void lcd_write(lcd_handle_t lcd_handle, char lcd_cmd_data, lcd_select_t cmd_or_data)
Writes data to LCD.
lcd_config::pin_backlight
pin_name_t pin_backlight
Definition: lcd.h:151
lcd_set_row
void lcd_set_row(lcd_handle_t lcd_handle, lcd_row_t row)
Sets current active row on LCD.
LCD_MODE_BIT_8
Definition: lcd.h:127
lcd_config::pin_d7
pin_name_t pin_d7
Definition: lcd.h:163
lcd_cursor_on
void lcd_cursor_on(lcd_handle_t lcd_handle)
Shows cursor.
lcd_config::pin_d5
pin_name_t pin_d5
Definition: lcd.h:161
lcd_err_t
lcd_err_t
Definition: lcd.h:106
lcd_config::pin_d6
pin_name_t pin_d6
Definition: lcd.h:162
lcd_handle
Definition: lcd.h:189
LCD_SELECT_DATA
Definition: lcd.h:118
pin_name_t
hal_pin_name_t pin_name_t
Definition: drv_name.h:73
lcd_mode_t
lcd_mode_t
Definition: lcd.h:124
lcd_handle::init_state
bool init_state
Init state.
Definition: lcd.h:208
lcd_cursor_move_right
void lcd_cursor_move_right(lcd_handle_t lcd_handle)
Moves cursor position.
init_sequence_ptr
void(* init_sequence_ptr)(uint32_t)
Init sequence prototype.
Definition: lcd.h:184
lcd_cursor_move_left
void lcd_cursor_move_left(lcd_handle_t lcd_handle)
Moves cursor position.
lcd_config::pin_d2
pin_name_t pin_d2
Definition: lcd.h:158
lcd_turn_off
void lcd_turn_off(lcd_handle_t lcd_handle)
Turns LCD OFF.
LCD_ROW_3
Definition: lcd.h:137
lcd_init
void lcd_init(lcd_handle_t lcd_handle, init_sequence_ptr init_sequence)
Initializes LCD.
LCD_SUCCESS
Definition: lcd.h:108
lcd_configure
lcd_err_t lcd_configure(lcd_handle_t *lcd_handle, lcd_config_t *config)
Configures LCD handle with passed configuration structure.
lcd_config::mode
lcd_mode_t mode
LCD mode.
Definition: lcd.h:169
LCD_MODE_BIT_4
Definition: lcd.h:126