Printe String in Display
This commit is contained in:
parent
824bc630cb
commit
3cd86e1b09
@ -5,6 +5,7 @@
|
|||||||
* Author: Carst
|
* Author: Carst
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <stm32g0xx_ll_gpio.h>
|
#include <stm32g0xx_ll_gpio.h>
|
||||||
#include "STM32G071KBT6.hpp"
|
#include "STM32G071KBT6.hpp"
|
||||||
#include "Display.hpp"
|
#include "Display.hpp"
|
||||||
@ -41,7 +42,11 @@ namespace ElektronischeLast
|
|||||||
switch (this->current_state)
|
switch (this->current_state)
|
||||||
{
|
{
|
||||||
case StateIdle:
|
case StateIdle:
|
||||||
// do nothing;
|
if(this->new_data)
|
||||||
|
{
|
||||||
|
this->new_data = false;
|
||||||
|
this->current_state = StateWriteData;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case StateDelay:
|
case StateDelay:
|
||||||
if(this->timer_elapsed())
|
if(this->timer_elapsed())
|
||||||
@ -109,6 +114,17 @@ namespace ElektronischeLast
|
|||||||
this->start_timer(1UL);
|
this->start_timer(1UL);
|
||||||
this->next_state = StateIdle;
|
this->next_state = StateIdle;
|
||||||
break;
|
break;
|
||||||
|
case StateWriteData:
|
||||||
|
write_data_4bit((std::uint8_t)this->string[this->pointer++]);
|
||||||
|
if(this->string[this->pointer] == '\0')
|
||||||
|
{
|
||||||
|
this->next_state = StateIdle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->next_state = StateWriteData;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -128,12 +144,14 @@ namespace ElektronischeLast
|
|||||||
|
|
||||||
void Display::set_cursor(Line_t line, std::uint32_t position)
|
void Display::set_cursor(Line_t line, std::uint32_t position)
|
||||||
{
|
{
|
||||||
|
lcd_cmd(0x80u | line | (position & 0x7F));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::print(const char* const string)
|
void Display::print(const char* const string)
|
||||||
{
|
{
|
||||||
|
strncpy(this->string, string, sizeof(this->string));
|
||||||
|
this->pointer = 0U;
|
||||||
|
this->new_data = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Display::timer_elapsed(void)
|
bool Display::timer_elapsed(void)
|
||||||
@ -179,4 +197,45 @@ namespace ElektronischeLast
|
|||||||
pulse_delay();
|
pulse_delay();
|
||||||
LL_GPIO_ResetOutputPin(GPIOB, PIN_E);
|
LL_GPIO_ResetOutputPin(GPIOB, PIN_E);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief write command to lcd and wait until busy is gone
|
||||||
|
/// \param[in] cmd command to transfer
|
||||||
|
void Display::lcd_cmd(uint8_t cmd)
|
||||||
|
{
|
||||||
|
write_command_4bit(cmd);
|
||||||
|
this->start_timer(1UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief write data to display
|
||||||
|
/// \param[in] data data which to write to display
|
||||||
|
void Display::lcd_data(uint8_t data)
|
||||||
|
{
|
||||||
|
write_data_4bit(data);
|
||||||
|
this->start_timer(1UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief write data to lcd in 4 bit mode
|
||||||
|
/// \details write data given by \p data to lcd.
|
||||||
|
/// First write upper nibble and in second step lower nibble
|
||||||
|
/// \param[in] data data to transfer
|
||||||
|
void Display::write_data_4bit(uint8_t data)
|
||||||
|
{
|
||||||
|
// RS=high, RW=low
|
||||||
|
LL_GPIO_SetOutputPin(GPIOB, PIN_RS | PIN_RW << GPIO_BSRR_BR0_Pos | PIN_E << GPIO_BSRR_BR0_Pos);
|
||||||
|
std::uint32_t tmp = data >> 4U;
|
||||||
|
tmp |= ((~(data >> 4U) & 0xFU) << GPIO_BSRR_BR0_Pos);
|
||||||
|
LL_GPIO_SetOutputPin(GPIOB, tmp);
|
||||||
|
__NOP();
|
||||||
|
LL_GPIO_SetOutputPin(GPIOB, PIN_E);
|
||||||
|
pulse_delay();
|
||||||
|
LL_GPIO_ResetOutputPin(GPIOB, PIN_E);
|
||||||
|
tmp = data & 0x0FU;
|
||||||
|
tmp |= ((~data & 0xFU) << GPIO_BSRR_BR0_Pos);
|
||||||
|
LL_GPIO_SetOutputPin(GPIOB, tmp);
|
||||||
|
__NOP();
|
||||||
|
LL_GPIO_SetOutputPin(GPIOB, PIN_E);
|
||||||
|
pulse_delay();
|
||||||
|
LL_GPIO_ResetOutputPin(GPIOB, PIN_E);
|
||||||
|
this->start_timer(1UL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ namespace ElektronischeLast
|
|||||||
StateInit08,
|
StateInit08,
|
||||||
StateInit09,
|
StateInit09,
|
||||||
StateInit10,
|
StateInit10,
|
||||||
|
StateWriteData,
|
||||||
} State_t;
|
} State_t;
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
@ -97,11 +97,16 @@ namespace ElektronischeLast
|
|||||||
State_t current_state;
|
State_t current_state;
|
||||||
State_t next_state;
|
State_t next_state;
|
||||||
std::uint32_t timer;
|
std::uint32_t timer;
|
||||||
|
char string[17];
|
||||||
|
std::uint8_t pointer;
|
||||||
|
bool new_data;
|
||||||
bool timer_elapsed(void);
|
bool timer_elapsed(void);
|
||||||
void start_timer(std::uint32_t timeout);
|
void start_timer(std::uint32_t timeout);
|
||||||
void wait_while_busy(void);
|
void lcd_cmd(uint8_t cmd);
|
||||||
|
void lcd_data(uint8_t data);
|
||||||
void write_command_8bit_4pin(std::uint32_t data);
|
void write_command_8bit_4pin(std::uint32_t data);
|
||||||
void write_command_4bit(std::uint32_t command);
|
void write_command_4bit(std::uint32_t command);
|
||||||
|
void write_data_4bit(uint8_t data);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +110,8 @@ int main (void)
|
|||||||
|
|
||||||
PIDController_Init(&pid);
|
PIDController_Init(&pid);
|
||||||
|
|
||||||
|
lcd.print("Miep Miep");
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
led.blink();
|
led.blink();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user