From 101cf426512de5f01845ec3269ad7bf404226405 Mon Sep 17 00:00:00 2001 From: Matteo Battilana Date: Wed, 22 Dec 2021 10:21:28 +0100 Subject: [PATCH] Moved parts for consistency --- include/i2c_lcd.h | 26 +++++++++++++++++++++++++- src/i2c_lcd.c | 25 +------------------------ src/main.c | 3 ++- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/i2c_lcd.h b/include/i2c_lcd.h index 48b5930..a2a3d39 100644 --- a/include/i2c_lcd.h +++ b/include/i2c_lcd.h @@ -1,5 +1,29 @@ #include "stm32f4xx_hal.h" +/*LCD Commands*/ +#define LCD_FUNCTION_SET1 0x31 +#define LCD_FUNCTION_SET2 0x22 +#define LCD_4BIT_2LINE_MODE 0x28 +#define LCD_DISP_CURS_ON 0x0E +#define LCD_DISP_ON_CURS_OFF 0x0C //Display on, cursor off +#define LCD_DISPLAY_OFF 0x08 +#define LCD_DISPLAY_ON 0x04 +#define LCD_CLEAR_DISPLAY 0x01 +#define LCD_ENTRY_MODE_SET 0x04 +#define LCD_INCREMENT_CURSER 0x06 +#define LCD_SET_ROW1_COL1 0x80 //Force cursor to beginning ( 1st line) +#define LCD_SET_ROW2_COL1 0xC0 //Force cursor to beginning ( 2nd line) +#define LCD_MOVE_DISPLAY_LEFT 0x18 +#define LCD_MOVE_DISPLAY_RIGHT 0x1C +#define LCD_CREATE_CHAR 0x40 + +#define SLAVE_ADDRESS_LCD 0x34<<1 // change this according to ur setup +#define LCD_BACKLIGHT 0x08 +#define LCD_NOBACKLIGHT 0x00 +#define EN 0x04 +#define RS 0x01 + + void lcd_init (I2C_HandleTypeDef * i2c_ref); // initialize lcd void lcd_create_char(char customChar[], int location); @@ -22,4 +46,4 @@ void lcd_send_two_string (char *str1, char * str2); void lcd_set_text_downloading(); -void lcd_set_number_people(int n_people, int max_people); \ No newline at end of file +void lcd_set_number_people(int n_people, int max_people); diff --git a/src/i2c_lcd.c b/src/i2c_lcd.c index 25a4085..0442cf0 100644 --- a/src/i2c_lcd.c +++ b/src/i2c_lcd.c @@ -3,29 +3,6 @@ #include "stm32f4xx_hal.h" #include "stdio.h" -/*LCD Commands*/ -#define LCD_FUNCTION_SET1 0x31 -#define LCD_FUNCTION_SET2 0x22 -#define LCD_4BIT_2LINE_MODE 0x28 -#define LCD_DISP_CURS_ON 0x0E -#define LCD_DISP_ON_CURS_OFF 0x0C //Display on, cursor off -#define LCD_DISPLAY_OFF 0x08 -#define LCD_DISPLAY_ON 0x04 -#define LCD_CLEAR_DISPLAY 0x01 -#define LCD_ENTRY_MODE_SET 0x04 -#define LCD_INCREMENT_CURSER 0x06 -#define LCD_SET_ROW1_COL1 0x80 //Force cursor to beginning ( 1st line) -#define LCD_SET_ROW2_COL1 0xC0 //Force cursor to beginning ( 2nd line) -#define LCD_MOVE_DISPLAY_LEFT 0x18 -#define LCD_MOVE_DISPLAY_RIGHT 0x1C -#define LCD_CREATE_CHAR 0x40 - -#define SLAVE_ADDRESS_LCD 0x34<<1 // change this according to ur setup -#define LCD_BACKLIGHT 0x08 -#define LCD_NOBACKLIGHT 0x00 -#define EN 0x04 -#define RS 0x01 - static I2C_HandleTypeDef *hi2c1; // https://maxpromer.github.io/LCD-Character-Creator/ @@ -146,4 +123,4 @@ void lcd_set_number_people(int n_people, int max_people){ lcd_send_string(" "); lcd_send_string(num_char); lcd_send_string(" "); -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c index 2159559..0905cc6 100644 --- a/src/main.c +++ b/src/main.c @@ -152,10 +152,11 @@ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); GPIO_InitStruct.Pin = RED_LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // pin 6 as pull up