Implemented KS0066 initialization

master
mandlm 2016-01-13 10:59:42 +01:00
parent 71661588b2
commit e60df4a6db
5 changed files with 224 additions and 20 deletions

179
LCD/LCD/KS0066.cpp Normal file
View File

@ -0,0 +1,179 @@
#include "KS0066.h"
#include <util/delay.h>
KS0066::KS0066(ShiftRegister &shiftRegister) : m_shiftRegister(shiftRegister)
{
initDisplay();
}
void KS0066::initDisplay()
{
_delay_ms(30);
functionSet(false, false, true);
onOffControl(true, true, true);
displayClear();
entryMode(true, false);
sendChar('i');
sendChar('n');
sendChar('i');
sendChar('t');
}
void KS0066::functionSet(bool interface8bit, bool twoLine, bool displayOn)
{
uint8_t command = 0b00100000;
if (interface8bit)
{
command |= (1 << 4);
}
if (twoLine)
{
command |= (1 << 3);
}
if (displayOn)
{
command |= (1 << 2);
}
sendCommand(command);
_delay_us(39);
}
void KS0066::onOffControl(bool displayOn, bool cursorOn, bool blinkingOn)
{
uint8_t command = 0b00001000;
if (displayOn)
{
command |= (1 << 2);
}
if (cursorOn)
{
command |= (1 << 1);
}
if (blinkingOn)
{
command |= (1 << 0);
}
sendCommand(command);
_delay_us(39);
}
void KS0066::displayClear()
{
uint8_t command = 0b00000001;
sendCommand(command);
_delay_ms(1.53);
}
void KS0066::entryMode(bool incrementMode, bool entireShift)
{
uint8_t command = 0b00000100;
if (incrementMode)
{
command |= (1 << 1);
}
if (entireShift)
{
command |= (1 << 0);
}
sendCommand(command);
_delay_us(39);
}
void KS0066::sendCommand(uint8_t data)
{
sendByte(data, true);
}
void KS0066::sendChar(char c)
{
sendByte(c, false);
_delay_us(43);
}
void KS0066::sendByte(uint8_t data, bool isCommand)
{
uint8_t registerValue = 0;
if (!isCommand)
{
registerValue |= (1 << m_rs);
}
if (data & (1 << 7))
{
registerValue |= (1 << m_db7);
}
if (data & (1 << 6))
{
registerValue |= (1 << m_db6);
}
if (data & (1 << 5))
{
registerValue |= (1 << m_db5);
}
if (data & (1 << 4))
{
registerValue |= (1 << m_db4);
}
execute(registerValue);
registerValue &= (1 << m_rs);
if (data & (1 << 3))
{
registerValue |= (1 << m_db7);
}
if (data & (1 << 3))
{
registerValue |= (1 << m_db6);
}
if (data & (1 << 1))
{
registerValue |= (1 << m_db5);
}
if (data & (1 << 0))
{
registerValue |= (1 << m_db4);
}
execute(registerValue);
}
void KS0066::execute(uint8_t registerValue)
{
registerValue |= (1 << m_e);
m_shiftRegister.output(registerValue);
_delay_us(2);
registerValue &= ~(1 << m_e);
m_shiftRegister.output(registerValue);
}

37
LCD/LCD/KS0066.h Normal file
View File

@ -0,0 +1,37 @@
#pragma once
#include <avr/io.h>
#include "ShiftRegister.h"
class KS0066
{
private:
ShiftRegister &m_shiftRegister;
static const uint8_t m_rs = 0;
static const uint8_t m_rw = 1;
static const uint8_t m_e = 2;
static const uint8_t m_db4 = 3;
static const uint8_t m_db5 = 4;
static const uint8_t m_db6 = 5;
static const uint8_t m_db7 = 6;
public:
KS0066(ShiftRegister &shiftRegister);
private:
void initDisplay();
void functionSet(bool interface8bit, bool twoLine, bool displayOn);
void onOffControl(bool displayOn, bool cursorOn, bool blinkingOn);
void displayClear();
void entryMode(bool incrementMode, bool entireShift);
void sendCommand(uint8_t data);
void sendChar(char c);
void sendByte(uint8_t data, bool isCommand);
void execute(uint8_t registerValue);
};

View File

@ -6,6 +6,7 @@
#include "Pin.h"
#include "ShiftRegister.h"
#include "KS0066.h"
int main(void)
{
@ -15,7 +16,7 @@ int main(void)
Pin ledPin(&PORTA, PA0);
// lcd initialization goes here
LCD lcd(shiftRegister);
KS0066 lcd(shiftRegister);
while(1)
{

View File

@ -133,6 +133,12 @@
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="KS0066.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="KS0066.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="LCD.cpp">
<SubType>compile</SubType>
</Compile>

View File

@ -17,22 +17,3 @@ public:
void output(int8_t value);
};
class LCD
{
private:
ShiftRegister &m_shiftRegister;
public:
LCD(ShiftRegister &shiftRegister)
: m_shiftRegister(shiftRegister)
{
}
private:
void init()
{
}
};