Restructured code into serveral source files

This commit is contained in:
mandlm 2016-01-12 22:47:20 +01:00
parent 7756a85bb9
commit 9abaa69d1e
6 changed files with 185 additions and 150 deletions

View File

@ -4,72 +4,8 @@
#include <avr/io.h>
#include <util/delay.h>
class Pin
{
public:
volatile uint8_t *m_port;
uint8_t m_pin;
public:
Pin(volatile uint8_t *port, uint8_t pin)
: m_port(port)
, m_pin(pin)
{
}
void pulse()
{
*m_port |= (1 << m_pin);
*m_port &= ~(1 << m_pin);
}
void set(bool value)
{
if (value == true)
{
*m_port |= (1 << m_pin);
}
else
{
*m_port &= ~(1 << m_pin);
}
}
void toggle()
{
*m_port ^= (1 << m_pin);
}
};
class ShiftRegister
{
Pin m_shiftClockPin;
Pin m_dataPin;
Pin m_latchClockPin;
public:
ShiftRegister(volatile uint8_t *shiftClockPort, uint8_t shiftClockPin,
volatile uint8_t *dataPort, uint8_t dataPin,
volatile uint8_t *latchClockPort, uint8_t latchClockPin)
: m_shiftClockPin(shiftClockPort, shiftClockPin)
, m_dataPin(dataPort, dataPin)
, m_latchClockPin(latchClockPort, latchClockPin)
{
}
void output(int8_t value)
{
for (int8_t bitIdx = 7; bitIdx >= 0; --bitIdx)
{
m_dataPin.set(value & (1 << bitIdx));
m_shiftClockPin.pulse();
}
m_latchClockPin.pulse();
}
};
#include "Pin.h"
#include "ShiftRegister.h"
int main(void)
{

View File

@ -36,7 +36,7 @@
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.29.0" />
</dependencies>
</framework-data>
</framework-data>
</AsfFrameworkConfig>
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
<com_atmel_avrdbg_tool_stk500>
@ -88,7 +88,7 @@
<Value>libm</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
</AvrGccCpp>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@ -129,13 +129,25 @@
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
</AvrGccCpp>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="LCD.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="Pin.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="Pin.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="ShiftRegister.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="ShiftRegister.h">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>

31
LCD/LCD/Pin.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "Pin.h"
Pin::Pin(volatile uint8_t *port, uint8_t pin) : m_port(port)
, m_pin(pin)
{
}
void Pin::pulse()
{
*m_port |= (1 << m_pin);
*m_port &= ~(1 << m_pin);
}
void Pin::set(bool value)
{
if (value == true)
{
*m_port |= (1 << m_pin);
}
else
{
*m_port &= ~(1 << m_pin);
}
}
void Pin::toggle()
{
*m_port ^= (1 << m_pin);
}

17
LCD/LCD/Pin.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <avr/io.h>
class Pin
{
private:
volatile uint8_t *m_port;
uint8_t m_pin;
public:
Pin(volatile uint8_t *port, uint8_t pin);
void pulse();
void set(bool value);
void toggle();
};

20
LCD/LCD/ShiftRegister.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "ShiftRegister.h"
ShiftRegister::ShiftRegister(volatile uint8_t *shiftClockPort, uint8_t shiftClockPin, volatile uint8_t *dataPort, uint8_t dataPin, volatile uint8_t *latchClockPort, uint8_t latchClockPin) : m_shiftClockPin(shiftClockPort, shiftClockPin)
, m_dataPin(dataPort, dataPin)
, m_latchClockPin(latchClockPort, latchClockPin)
{
}
void ShiftRegister::output(int8_t value)
{
for (int8_t bitIdx = 7; bitIdx >= 0; --bitIdx)
{
m_dataPin.set(value & (1 << bitIdx));
m_shiftClockPin.pulse();
}
m_latchClockPin.pulse();
}

19
LCD/LCD/ShiftRegister.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include <avr/io.h>
#include "Pin.h"
class ShiftRegister
{
Pin m_shiftClockPin;
Pin m_dataPin;
Pin m_latchClockPin;
public:
ShiftRegister(volatile uint8_t *shiftClockPort, uint8_t shiftClockPin,
volatile uint8_t *dataPort, uint8_t dataPin,
volatile uint8_t *latchClockPort, uint8_t latchClockPin);
void output(int8_t value);
};