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 <avr/io.h>
#include <util/delay.h> #include <util/delay.h>
class Pin #include "Pin.h"
{ #include "ShiftRegister.h"
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();
}
};
int main(void) int main(void)
{ {

View file

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