2017-02-24 20:45:37 +00:00
|
|
|
#include "Lcd.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
void Lcd::initDisplay()
|
|
|
|
{
|
|
|
|
static const Command resetCommand{0, 0, 0, 0, 1, 1, 0, 0};
|
2017-03-02 07:16:35 +00:00
|
|
|
static const Command fourBitModeCommand{0, 1, 0, 0, 0, 0, 0, 0};
|
|
|
|
static const Command functionSetCommand{0, 0, 1, 1, 0, 1, 0, 0};
|
|
|
|
static const Command displayOnOffCommand{0, 0, 1, 1, 0, 0, 0, 0};
|
|
|
|
static const Command entryModeCommand{0, 1, 1, 0, 0, 0, 0, 0};
|
|
|
|
|
|
|
|
execute(resetCommand, false, 5000);
|
|
|
|
execute(resetCommand, false, 100);
|
|
|
|
execute(resetCommand, false, 0);
|
|
|
|
|
|
|
|
execute(fourBitModeCommand, false, 0);
|
|
|
|
execute(functionSetCommand, false, 39);
|
|
|
|
execute(displayOnOffCommand, false, 39);
|
2017-02-24 20:45:37 +00:00
|
|
|
clear();
|
2017-03-02 07:16:35 +00:00
|
|
|
execute(entryModeCommand, false, 39);
|
2017-02-24 20:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lcd::clear()
|
|
|
|
{
|
2017-03-02 07:16:35 +00:00
|
|
|
execute({1, 0, 0, 0, 0, 0, 0, 0}, false, 1530);
|
2017-02-24 20:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lcd::setPos(const uint8_t &pos)
|
|
|
|
{
|
|
|
|
Command posCommand;
|
|
|
|
posCommand.data = pos | (1 << 7);
|
|
|
|
|
2017-03-02 07:16:35 +00:00
|
|
|
execute(posCommand, false, 39);
|
2017-02-24 20:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lcd::output(const char &character)
|
|
|
|
{
|
2017-03-02 07:16:35 +00:00
|
|
|
execute((const Command &)character, true, 43);
|
2017-02-24 20:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Lcd::output(const char *string)
|
|
|
|
{
|
|
|
|
uint8_t pos = 0;
|
|
|
|
while (string != nullptr && *string != 0)
|
|
|
|
{
|
|
|
|
if (pos == 8)
|
|
|
|
{
|
|
|
|
setPos(40);
|
|
|
|
}
|
|
|
|
output(*string++);
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:16:35 +00:00
|
|
|
void Lcd::output(const uint16_t val)
|
2017-02-24 20:45:37 +00:00
|
|
|
{
|
|
|
|
static char buf[5];
|
|
|
|
output(itoa(val, buf, 10));
|
|
|
|
}
|
|
|
|
|