22static uint8_t write_nibble(i2c_master_dev_handle_t handle, uint8_t nibble,
bool rs) {
23 uint8_t data = (nibble & 0xF0);
33 return i2c_master_transmit(handle, sequence,
sizeof(sequence),
I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
44static uint8_t send_command(i2c_master_dev_handle_t handle, uint8_t cmd) {
47 uint8_t high = cmd & 0xF0;
48 uint8_t low = (cmd << 4) & 0xF0;
50 err = write_nibble(handle, high,
false);
51 vTaskDelay(pdMS_TO_TICKS(2));
52 err = write_nibble(handle, low,
false);
53 vTaskDelay(pdMS_TO_TICKS(2));
66static uint8_t send_char(i2c_master_dev_handle_t handle,
char c) {
69 uint8_t high = c & 0xF0;
70 uint8_t low = (c << 4) & 0xF0;
72 err = write_nibble(handle, high,
true);
73 vTaskDelay(pdMS_TO_TICKS(2));
74 err = write_nibble(handle, low,
true);
75 vTaskDelay(pdMS_TO_TICKS(2));
87static uint8_t clear_screen(i2c_master_dev_handle_t handle) {
89 vTaskDelay(pdMS_TO_TICKS(10));
102static uint8_t lcd_goto(i2c_master_dev_handle_t handle, uint8_t x, uint8_t y) {
103 static const uint8_t row_offsets[] = { 0x00, 0x40 };
105 uint8_t err = send_command(handle, 0x80 | (row_offsets[y] + x));
107 vTaskDelay(pdMS_TO_TICKS(10));
112 clear_screen(handle);
114 uint8_t char_len = 0;
117 while(*str !=
'\0') {
118 if(*str ==
'\n' || char_len >= 16) {
120 lcd_goto(handle, 0,1);
133 send_char(handle, *str);
147 vTaskDelay(pdMS_TO_TICKS(15));
148 write_nibble(handle, (0x03 << 4), 0);
149 vTaskDelay(pdMS_TO_TICKS(5));
150 write_nibble(handle, (0x03 << 4), 0);
151 vTaskDelay(pdMS_TO_TICKS(2));
152 write_nibble(handle, (0x03 << 4), 0);
153 vTaskDelay(pdMS_TO_TICKS(2));
154 write_nibble(handle, (0x02 << 4), 0);
159 clear_screen(handle);
#define LCD_1602_MAX_ROWS
LCD_WRITE_STATUS lcd_1602_send_string(i2c_master_dev_handle_t handle, char *str)
Writes out data to the LCD.
uint8_t lcd_1602_init(i2c_master_dev_handle_t handle)
initializes the LCD 1602 correctly according to the datasheet.
#define LCD_1602_FUNCTION_SET(dl, r, f)
Macro for configuring the lcd screens function. Use together with:
#define LCD_1602_CONFIG_INPUT_SET(dir, mov)
Macro for setting the correct movement of the cursor. Use together with:
#define LCD_1602_CONFIG_DISPLAY_SWITCH(disp, curs, blink)
Macro for configuring the display settings. Use together with;.
LCD_WRITE_STATUS
Enum for returning the result of writing to the LCD.
#define LCD_1602_N_BLINK_DISPLAY
#define LCD_1602_DISPLAY_ON
#define LCD_1602_CLEAR_SCREEN
#define LCD_1602_CURSOR_OFF
#define LCD_1602_BACKLIGHT
#define LCD_1602_INCREMENT_MODE
#define LCD_1602_FONT_5X10
#define LCD_1602_CURSOR_N_MOVE
#define LCD_1602_DATA_LEN_4_BIT
: Internal implementation of the LCD1602
#define I2C_MASTER_TIMEOUT_MS