Added DEM16101 (KS0066) display class

This commit is contained in:
Michael Mandl 2017-02-24 21:45:37 +01:00
parent 9f8ad33723
commit d9ac375268
2 changed files with 101 additions and 0 deletions

64
Lcd.cpp Normal file
View file

@ -0,0 +1,64 @@
#include "Lcd.h"
#include <stdlib.h>
void Lcd::initDisplay()
{
static const Command resetCommand{0, 0, 0, 0, 1, 1, 0, 0};
execute(resetCommand, false, 5.0);
execute(resetCommand, false, 0.1);
execute(resetCommand, false, 0.0);
execute({0, 1, 0, 0, 0, 0, 0, 0}, false, 0.0);
// function set
execute({0, 0, 1, 1, 0, 1, 0, 0}, false, 0.039);
// display on/off
execute({0, 0, 1, 1, 0, 0, 0, 0}, false, 0.039);
clear();
// entry mode
execute({0, 1, 1, 0, 0, 0, 0, 0}, false, 0.039);
}
void Lcd::clear()
{
execute({1, 0, 0, 0, 0, 0, 0, 0}, false, 1.53);
}
void Lcd::setPos(const uint8_t &pos)
{
Command posCommand;
posCommand.data = pos | (1 << 7);
execute(posCommand, false, 0.039);
}
void Lcd::output(const char &character)
{
execute((const Command &)character, true, 0.043);
}
void Lcd::output(const char *string)
{
uint8_t pos = 0;
while (string != nullptr && *string != 0)
{
if (pos == 8)
{
setPos(40);
}
output(*string++);
pos++;
}
}
void Lcd::output(const uint16_t &val)
{
static char buf[5];
output(itoa(val, buf, 10));
}

37
Lcd.h Normal file
View file

@ -0,0 +1,37 @@
#pragma once
#include <stdint.h>
class Lcd
{
public:
union Command
{
struct
{
bool DB0: 1;
bool DB1: 1;
bool DB2: 1;
bool DB3: 1;
bool DB4: 1;
bool DB5: 1;
bool DB6: 1;
bool DB7: 1;
};
uint8_t data;
};
public:
void initDisplay();
void clear();
void output(const char &character);
void output(const char *string);
void output(const uint16_t &val);
private:
void setPos(const uint8_t &pos);
virtual void execute(const Command &cmd, bool RS, double delay) = 0;
};