diff --git a/LCD/LCD/LCD.cpp b/LCD/LCD/LCD.cpp index c5364bf..a61ac55 100644 --- a/LCD/LCD/LCD.cpp +++ b/LCD/LCD/LCD.cpp @@ -4,72 +4,8 @@ #include #include -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) { @@ -77,13 +13,13 @@ int main(void) ShiftRegister shiftRegister(&PORTA, PA1, &PORTA, PA3, &PORTA, PA2); Pin ledPin(&PORTA, PA0); - + // lcd initialization goes here - - - while(1) - { + + + while(1) + { ledPin.toggle(); _delay_ms(125); - } + } } \ No newline at end of file diff --git a/LCD/LCD/LCD.cppproj b/LCD/LCD/LCD.cppproj index 2dbc22c..c19627f 100644 --- a/LCD/LCD/LCD.cppproj +++ b/LCD/LCD/LCD.cppproj @@ -28,15 +28,15 @@ 0 - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.stk500 @@ -56,86 +56,98 @@ - True - True - True - True - False - True - True - - - NDEBUG - - - Optimize for size (-Os) - True - True - True - True - True - - - NDEBUG - - - Optimize for size (-Os) - True - True - True - - - libm - - - + True + True + True + True + False + True + True + + + NDEBUG + + + Optimize for size (-Os) + True + True + True + True + True + + + NDEBUG + + + Optimize for size (-Os) + True + True + True + + + libm + + + - True - True - True - True - False - True - True - - - DEBUG - - - Optimize (-O1) - True - True - Default (-g2) - True - True - True - - - DEBUG - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - + True + True + True + True + False + True + True + + + DEBUG + + + Optimize (-O1) + True + True + Default (-g2) + True + True + True + + + DEBUG + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + compile + + compile + + + compile + + + compile + + + compile + \ No newline at end of file diff --git a/LCD/LCD/Pin.cpp b/LCD/LCD/Pin.cpp new file mode 100644 index 0000000..4537eb9 --- /dev/null +++ b/LCD/LCD/Pin.cpp @@ -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); +} + diff --git a/LCD/LCD/Pin.h b/LCD/LCD/Pin.h new file mode 100644 index 0000000..af82b9f --- /dev/null +++ b/LCD/LCD/Pin.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +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(); +}; diff --git a/LCD/LCD/ShiftRegister.cpp b/LCD/LCD/ShiftRegister.cpp new file mode 100644 index 0000000..9ac7173 --- /dev/null +++ b/LCD/LCD/ShiftRegister.cpp @@ -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(); +} + diff --git a/LCD/LCD/ShiftRegister.h b/LCD/LCD/ShiftRegister.h new file mode 100644 index 0000000..a2b2e4d --- /dev/null +++ b/LCD/LCD/ShiftRegister.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#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); +};