Restructured code into serveral source files
This commit is contained in:
parent
7756a85bb9
commit
9abaa69d1e
@ -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)
|
||||
{
|
||||
|
@ -136,6 +136,18 @@
|
||||
<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
31
LCD/LCD/Pin.cpp
Normal 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
17
LCD/LCD/Pin.h
Normal 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
20
LCD/LCD/ShiftRegister.cpp
Normal 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
19
LCD/LCD/ShiftRegister.h
Normal 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);
|
||||
};
|
Reference in New Issue
Block a user