-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples of library implementation on various hardware configurations have been added. 1. ATMEGA328P_ARDUINO_UNO_R3 2. STM32G071RB_NUCLEO_BARE_METAL 3. STM32G071RB_NUCLEO_BARE_METAL
- Loading branch information
Showing
143 changed files
with
74,729 additions
and
21,526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
#define ON 1 | ||
#define OFF 0 | ||
|
||
#define DEBUG_CONSOLE ON | ||
#define DEBUG_CONSOLE OFF | ||
|
||
#ifdef __cplusplus | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* @Author: lukasz.niewelt | ||
* @Date: 2023-12-04 20:13:23 | ||
* @Last Modified by: lukasz.niewelt | ||
* @Last Modified time: 2023-12-08 10:49:44 | ||
*/ | ||
|
||
// #include "lcd_hd44780_config.h" | ||
#include "lcd_hd44780_interface.h" | ||
#include "lcd_hd44780_config.h" | ||
#include <stdio.h> | ||
#include <avr/io.h> | ||
#include <util/delay.h> | ||
|
||
#define LCD_DATA_PORT PORTD | ||
#define LCD_DATA_PORT_DIR DDRD | ||
#define LCD_DATA_INPUT PIND | ||
|
||
#define LCD_SIG_PORT PORTB | ||
#define LCD_SIG_PORT_DIR DDRB | ||
|
||
#define LCD_BCKL_PORT PORTB | ||
#define LCD_BCKL_PORT_DIR DDRB | ||
|
||
#define LCD_PIN_D7 (1 << PIND7) | ||
#define LCD_PIN_D6 (1 << PIND6) | ||
#define LCD_PIN_D5 (1 << PIND5) | ||
#define LCD_PIN_D4 (1 << PIND4) | ||
#define LCD_PIN_RS (1 << PINB0) | ||
#define LCD_PIN_RW (1 << PINC1) | ||
#define LCD_PIN_E (1 << PINB1) | ||
#define LCD_BCKL_PIN (1 << PINB5) | ||
|
||
#define LCD_D4_MASK 0x01 | ||
#define LCD_D5_MASK 0x02 | ||
#define LCD_D6_MASK 0x04 | ||
#define LCD_D7_MASK 0x08 | ||
|
||
static void init_LCD_data_and_SIG_pins(void); | ||
static void init_LCD_DATA_PINS_as_outputs(void); | ||
static void init_LCD_DATA_PINS_as_inputs(void); | ||
static void set_LCD_DATA_PINS_state(uint8_t data); | ||
static uint8_t get_LCD_DATA_PINS_state(void); | ||
static void init_LCD_SIGNAL_PINS_as_outputs(void); | ||
static void LCD_set_SIG(enum lcd_sig LCD_SIG); | ||
static void LCD_reset_SIG(enum lcd_sig LCD_SIG); | ||
static void wraper_delay_us(uint32_t delay_us); | ||
|
||
/************LCD_IO_driver_interface implementation START**************/ | ||
static const struct LCD_IO_driver_interface_struct LCD_IO_driver = { | ||
init_LCD_data_and_SIG_pins, | ||
init_LCD_DATA_PINS_as_outputs, | ||
init_LCD_DATA_PINS_as_inputs, | ||
set_LCD_DATA_PINS_state, | ||
get_LCD_DATA_PINS_state, | ||
init_LCD_SIGNAL_PINS_as_outputs, | ||
LCD_set_SIG, | ||
LCD_reset_SIG, | ||
wraper_delay_us, | ||
}; | ||
const struct LCD_IO_driver_interface_struct *LCD_IO_driver_interface_get(void) | ||
{ | ||
return &LCD_IO_driver; | ||
} | ||
|
||
/*************LCD_IO_driver_interface implementation END***************/ | ||
|
||
static void init_LCD_data_and_SIG_pins(void) | ||
{ | ||
//set BCKL PIN as output | ||
LCD_BCKL_PORT_DIR |= LCD_BCKL_PIN; | ||
//enable Backlight of the LCD | ||
LCD_BCKL_PORT |= LCD_BCKL_PIN; | ||
init_LCD_DATA_PINS_as_outputs(); | ||
init_LCD_SIGNAL_PINS_as_outputs(); | ||
} | ||
static void init_LCD_DATA_PINS_as_outputs(void) | ||
{ | ||
//set pins as output | ||
LCD_DATA_PORT_DIR |= (LCD_PIN_D4 | LCD_PIN_D5 | LCD_PIN_D6 | LCD_PIN_D7); | ||
} | ||
static void init_LCD_DATA_PINS_as_inputs(void) | ||
{ | ||
|
||
//set pins as inputs | ||
LCD_DATA_PORT_DIR &= ~(LCD_PIN_D4 | LCD_PIN_D5 | LCD_PIN_D6 | LCD_PIN_D7); | ||
// enable pull-up on input pins | ||
LCD_DATA_PORT |= (LCD_PIN_D4 | LCD_PIN_D5 | LCD_PIN_D6 | LCD_PIN_D7); | ||
} | ||
|
||
static void set_LCD_DATA_PINS_state(uint8_t data) | ||
{ | ||
if ((data & LCD_D4_MASK)) | ||
LCD_DATA_PORT |= LCD_PIN_D4; | ||
else | ||
LCD_DATA_PORT &= ~LCD_PIN_D4; | ||
|
||
if ((data & LCD_D5_MASK)) | ||
LCD_DATA_PORT |= LCD_PIN_D5; | ||
else | ||
LCD_DATA_PORT &= ~LCD_PIN_D5; | ||
|
||
if ((data & LCD_D6_MASK)) | ||
LCD_DATA_PORT |= LCD_PIN_D6; | ||
else | ||
LCD_DATA_PORT &= ~LCD_PIN_D6; | ||
|
||
if ((data & LCD_D7_MASK)) | ||
LCD_DATA_PORT |= LCD_PIN_D7; | ||
else | ||
LCD_DATA_PORT &= ~LCD_PIN_D7; | ||
} | ||
|
||
static uint8_t get_LCD_DATA_PINS_state(void) | ||
{ | ||
uint8_t data = 0; | ||
if (LCD_DATA_INPUT & LCD_PIN_D4) | ||
data = LCD_D4_MASK; | ||
if (LCD_DATA_INPUT & LCD_PIN_D5) | ||
data |= LCD_D5_MASK; | ||
if (LCD_DATA_INPUT & LCD_PIN_D6) | ||
data |= LCD_D6_MASK; | ||
if (LCD_DATA_INPUT & LCD_PIN_D7) | ||
data |= LCD_D7_MASK; | ||
return data; | ||
} | ||
|
||
static void init_LCD_SIGNAL_PINS_as_outputs(void) | ||
{ | ||
#if USE_RW_PIN == ON | ||
LCD_SIG_PORT_DIR |= (LCD_PIN_RS | LCD_PIN_RW | LCD_PIN_E); | ||
|
||
#else | ||
LCD_SIG_PORT_DIR |= (LCD_PIN_RS | LCD_PIN_E); | ||
#endif | ||
} | ||
|
||
static void LCD_set_SIG(enum lcd_sig LCD_SIG) | ||
{ | ||
switch (LCD_SIG) | ||
{ | ||
case LCD_RS: | ||
LCD_SIG_PORT |= LCD_PIN_RS; | ||
break; | ||
case LCD_E: | ||
LCD_SIG_PORT |= LCD_PIN_E; | ||
break; | ||
#if USE_RW_PIN == ON | ||
case LCD_RW: | ||
LCD_SIG_PORT |= LCD_PIN_RW; | ||
break; | ||
#endif | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
static void LCD_reset_SIG(enum lcd_sig LCD_SIG) | ||
{ | ||
switch (LCD_SIG) | ||
{ | ||
case LCD_RS: | ||
LCD_SIG_PORT &= ~LCD_PIN_RS; | ||
break; | ||
case LCD_E: | ||
LCD_SIG_PORT &= ~LCD_PIN_E; | ||
break; | ||
#if USE_RW_PIN == ON | ||
case LCD_RW: | ||
LCD_SIG_PORT &= ~LCD_PIN_RW; | ||
break; | ||
#endif | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void wraper_delay_us(uint32_t delay_us) | ||
{ | ||
_delay_us((double)(delay_us)); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
#include <avr/io.h> | ||
#include <util/delay.h> | ||
#include <string.h> | ||
#include "project_config.h" | ||
#if DEBUG_CONSOLE == ON | ||
#include "debug.h" | ||
#endif | ||
#include "lcd_hd44780.h" | ||
|
||
#define SHIFT_DELAY 400 | ||
|
||
const char *demo_tekst = {"Congratulation, you have just run LCD demo example."}; | ||
const char *demo_title = {"LCD HD44780 Demo"}; | ||
|
||
static void lcd_buf_slide_str_in(const char *str, enum LCD_LINES lcd_line, uint16_t speed); | ||
static void lcd_buf_slide_str_out(const char *str, enum LCD_LINES lcd_line, uint16_t speed); | ||
|
||
uint8_t j = 0; | ||
uint8_t i = 0; | ||
|
||
int main(void) | ||
{ | ||
|
||
#if DEBUG_CONSOLE == ON | ||
// Init the debug UART allowing us to use `printf` | ||
debug_console_init(); | ||
#endif | ||
lcd_init(); | ||
lcd_buf_str(demo_title); | ||
lcd_update(); | ||
while (1) | ||
{ | ||
lcd_buf_slide_str_in(demo_tekst, LINE_2, SHIFT_DELAY); | ||
lcd_buf_slide_str_out(demo_tekst, LINE_2, SHIFT_DELAY); | ||
} | ||
return 0; | ||
} | ||
|
||
void lcd_buf_slide_str_out(const char *str, enum LCD_LINES lcd_line, uint16_t speed) | ||
{ | ||
uint8_t str_end_flag = 0; | ||
for (j = 0; j <= strlen(str); j++) | ||
{ | ||
_delay_ms(speed); | ||
lcd_buf_locate(lcd_line, C1); | ||
for (i = 0; i < LCD_X; i++) | ||
{ | ||
if ((str[j + i] != '\0') && (str_end_flag == 0)) | ||
{ | ||
lcd_buf_char(str[j + i]); | ||
} | ||
else | ||
{ | ||
str_end_flag = 0xFF; | ||
lcd_buf_char(' '); | ||
} | ||
} | ||
str_end_flag = 0; | ||
lcd_update(); | ||
} | ||
} | ||
|
||
void lcd_buf_slide_str_in(const char *str, enum LCD_LINES lcd_line, uint16_t speed) | ||
{ | ||
for (i = LCD_X - 1; i > C1; i--) | ||
{ | ||
_delay_ms(speed); | ||
lcd_buf_locate(lcd_line, i); | ||
for (uint8_t j = 0; j < (LCD_X - i); j++) | ||
{ | ||
lcd_buf_char(str[j]); | ||
} | ||
lcd_update(); | ||
} | ||
} |
Oops, something went wrong.