diff --git a/TWI/TWI.atsln b/TWI/TWI.atsln new file mode 100644 index 0000000..5a87728 --- /dev/null +++ b/TWI/TWI.atsln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Atmel Studio Solution File, Format Version 11.00 +Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "TWI", "TWI\TWI.cppproj", "{46349E95-E546-4344-8620-E0A6F53C8C82}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {46349E95-E546-4344-8620-E0A6F53C8C82}.Debug|AVR.ActiveCfg = Debug|AVR + {46349E95-E546-4344-8620-E0A6F53C8C82}.Debug|AVR.Build.0 = Debug|AVR + {46349E95-E546-4344-8620-E0A6F53C8C82}.Release|AVR.ActiveCfg = Release|AVR + {46349E95-E546-4344-8620-E0A6F53C8C82}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/TWI/TWI/Pin.cpp b/TWI/TWI/Pin.cpp new file mode 100644 index 0000000..fed245b --- /dev/null +++ b/TWI/TWI/Pin.cpp @@ -0,0 +1,43 @@ +#include "Pin.h" + +#include "environment.h" + +#include + +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); +} + +void Pin::blink() +{ + *m_port |= (1 << m_pin); + _delay_ms(50); + *m_port &= ~(1 << m_pin); +} + diff --git a/TWI/TWI/Pin.h b/TWI/TWI/Pin.h new file mode 100644 index 0000000..6b51006 --- /dev/null +++ b/TWI/TWI/Pin.h @@ -0,0 +1,19 @@ +#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(); + + void blink(); +}; diff --git a/TWI/TWI/TWI.cpp b/TWI/TWI/TWI.cpp new file mode 100644 index 0000000..dc0c91e --- /dev/null +++ b/TWI/TWI/TWI.cpp @@ -0,0 +1,63 @@ +#include "environment.h" + +#include +#include + +#include +#include + +#include "Pin.h" + +void I2C_init(uint8_t address) +{ + // load address into TWI address register + TWAR = (address << 1); + + // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt + TWCR = (1< + + + 2.0 + 6.2 + com.Atmel.AVRGCC8.CPP + {46349e95-e546-4344-8620-e0a6f53c8c82} + ATmega32 + none + Executable + CPP + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + TWI + TWI + TWI + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + + + + + + + + + + + + + com.atmel.avrdbg.tool.stk500 + + + + 125000 + + ISP + + com.atmel.avrdbg.tool.stk500 + + + STK500 + + ISP + + + + + 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) + + + + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/TWI/TWI/environment.h b/TWI/TWI/environment.h new file mode 100644 index 0000000..c05c7f5 --- /dev/null +++ b/TWI/TWI/environment.h @@ -0,0 +1,3 @@ +#pragma once + +#define F_CPU 12000000 \ No newline at end of file