diff --git a/.gitmodules b/.gitmodules index 2ed4068..98674a7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "PID"] path = PID url = https://github.com/Carsten1987/PID.git +[submodule "lcd_16x2"] + path = lcd_16x2 + url = http://gitea.keller/carsten/lcd_16x2.git diff --git a/Source/Display.cpp b/Source/Display.cpp new file mode 100644 index 0000000..9e84be3 --- /dev/null +++ b/Source/Display.cpp @@ -0,0 +1,87 @@ +/* + * Display.cpp + * + * Created on: Jul 29, 2023 + * Author: Carst + */ + +#include +#include +#include +#include +#include "Display.hpp" +#include "lcd_1602.h" + +extern "C" void LCD_RS_SetLow(void) +{ + LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_4); +} +extern "C" void LCD_RS_SetHigh(void) +{ + LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_4); +} +extern "C" void LCD_RW_SetLow(void) +{ + LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_5); +} +extern "C" void LCD_RW_SetHigh(void) +{ + LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5); +} +extern "C" void LCD_E_SetLow(void) +{ + LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_6); +} +extern "C" void LCD_E_SetHigh(void) +{ + LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6); +} +extern "C" void LCD_DB_Set(uint8_t data) +{ + LL_GPIO_SetOutputPin(GPIOB, data); + LL_GPIO_ResetOutputPin(GPIOB, ~data & 0x0FUL); +} +extern "C" uint8_t LCD_DB_Get(void) +{ + return LL_GPIO_ReadInputPort(GPIOB); +} +extern "C" void LCD_DB_ConfigInput(void) +{ + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0, LL_GPIO_MODE_INPUT); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_1, LL_GPIO_MODE_INPUT); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_2, LL_GPIO_MODE_INPUT); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_INPUT); +} +extern "C" void LCD_DB_ConfigOutput(void) +{ + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0, LL_GPIO_MODE_OUTPUT); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_1, LL_GPIO_MODE_OUTPUT); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_2, LL_GPIO_MODE_OUTPUT); + LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_OUTPUT); + +} +namespace ElektronischeLast +{ + Display::Display(void) + { + lcd_init(); + } + + Display::~Display(void) + { + + } + void Display::NewData(uint32_t strom, uint32_t spannung, uint32_t temperatur) + { + char buf[17]; // 16 Zeichen pro Zeile + \0 + snprintf(buf, 16, "U: %2" PRIu32 ".%" PRIu32 " T: %2" PRIu32 ".%1" PRIu32, + spannung / 1000UL, spannung %1000UL, temperatur, 0UL); + lcd_set_cursor(eLine1, 0U); + lcd_string(buf); + + snprintf(buf, 16, "I: %2" PRIu32 ".%" PRIu32 " P: %4" PRIu32, + strom / 1000UL, strom %1000UL, strom * spannung / 1000UL); + lcd_string(buf); + lcd_set_cursor(eLine2, 0U); + } +} diff --git a/Source/Display.hpp b/Source/Display.hpp new file mode 100644 index 0000000..ec03998 --- /dev/null +++ b/Source/Display.hpp @@ -0,0 +1,45 @@ +/* + * Display.hpp + * + * Created on: Jul 29, 2023 + * Author: Carst + */ + +#ifndef DISPLAY_HPP_ +#define DISPLAY_HPP_ + +#ifdef __cplusplus + extern "C" { + #include +#else + #include +#endif + +void LCD_RS_SetLow(void); +void LCD_RS_SetHigh(void); +void LCD_RW_SetLow(void); +void LCD_RW_SetHigh(void); +void LCD_E_SetLow(void); +void LCD_E_SetHigh(void); +void LCD_DB_Set(uint8_t data); // Write data +uint8_t LCD_DB_Get(void); // Read Data +void LCD_DB_ConfigInput(void); // Konfiguriere I/O als Input +void LCD_DB_ConfigOutput(void); // Konfiguriere I/O als Output + +#ifdef __cplusplus +namespace ElektronischeLast +{ + class Display + { + public: + Display(void); + ~Display(void); + void NewData(uint32_t strom, uint32_t spannung, uint32_t temperatur); + }; +} +#endif +#ifdef __cplusplus + } +#endif + +#endif /* DISPLAY_HPP_ */ diff --git a/Source/ElektronischeLast.cpp b/Source/ElektronischeLast.cpp index a17ee80..6a7d40f 100644 --- a/Source/ElektronischeLast.cpp +++ b/Source/ElektronischeLast.cpp @@ -17,6 +17,7 @@ #include "serial.hpp" #include "PID.h" #include "FanControl.hpp" +#include "Display.hpp" #include "CLI.h" using namespace ElektronischeLast; @@ -59,7 +60,9 @@ int main (void) iDAC dac = iDAC(); iADC adc = iADC(); FanControl fan = FanControl(); + Display display = Display(); std::uint32_t last_tick = systick; + std::uint32_t sec_tick = systick; printf("\r\nElektronische Last\r\n"); printf("- Initialisierung erfolgreich\r\n"); @@ -85,6 +88,11 @@ int main (void) serial_cyclic(); } + if(sec_tick + 1000UL > systick) + { + sec_tick = systick; + display.NewData(strom, spannung, temperatur); + } } } diff --git a/Source/lcd_16x2_config.h b/Source/lcd_16x2_config.h new file mode 100644 index 0000000..f412741 --- /dev/null +++ b/Source/lcd_16x2_config.h @@ -0,0 +1,18 @@ +/* + * lcd_16x2_config.h + * + * Created on: Jul 29, 2023 + * Author: Carst + */ + +#ifndef LCD_16X2_CONFIG_H_ +#define LCD_16X2_CONFIG_H_ + +#include +#include "Display.hpp" + +#define NOP __NOP +#define __delay_ms(x) { for(int i=0;i