Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Public Projects
bcd-clock
Commits
bebfc2eb
Commit
bebfc2eb
authored
Nov 13, 2017
by
Alexander Detsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
941323e2
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
540 additions
and
273 deletions
+540
-273
Software/Firmware/Binaeruhr/.vs/Binaeruhr/v14/.atsuo
Software/Firmware/Binaeruhr/.vs/Binaeruhr/v14/.atsuo
+0
-0
Software/Firmware/Binaeruhr/Binaeruhr/Binaeruhr.cppproj
Software/Firmware/Binaeruhr/Binaeruhr/Binaeruhr.cppproj
+95
-93
Software/Firmware/Binaeruhr/Binaeruhr/lib/CLOCK.cpp
Software/Firmware/Binaeruhr/Binaeruhr/lib/CLOCK.cpp
+9
-9
Software/Firmware/Binaeruhr/Binaeruhr/lib/CLOCK.h
Software/Firmware/Binaeruhr/Binaeruhr/lib/CLOCK.h
+9
-9
Software/Firmware/Binaeruhr/Binaeruhr/lib/SHIFTREGISTER.cpp
Software/Firmware/Binaeruhr/Binaeruhr/lib/SHIFTREGISTER.cpp
+9
-10
Software/Firmware/Binaeruhr/Binaeruhr/lib/SHIFTREGISTER.h
Software/Firmware/Binaeruhr/Binaeruhr/lib/SHIFTREGISTER.h
+12
-13
Software/Firmware/Binaeruhr/Binaeruhr/lib/UART.cpp
Software/Firmware/Binaeruhr/Binaeruhr/lib/UART.cpp
+298
-67
Software/Firmware/Binaeruhr/Binaeruhr/lib/UART.h
Software/Firmware/Binaeruhr/Binaeruhr/lib/UART.h
+100
-61
Software/Firmware/Binaeruhr/Binaeruhr/main.cpp
Software/Firmware/Binaeruhr/Binaeruhr/main.cpp
+8
-11
No files found.
Software/Firmware/Binaeruhr/.vs/Binaeruhr/v14/.atsuo
View file @
bebfc2eb
No preview for this file type
Software/Firmware/Binaeruhr/Binaeruhr/Binaeruhr.cppproj
View file @
bebfc2eb
...
...
@@ -61,108 +61,110 @@
</com_atmel_avrdbg_tool_avrdragon>
<avrtoolinterface>
ISP
</avrtoolinterface>
<avrtoolinterfaceclock>
125000
</avrtoolinterfaceclock>
<ResetRule>
0
</ResetRule>
<EraseKey
/>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)' == 'Release' "
>
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>
-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\gcc\dev\atmega328p"
</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>
True
</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>
True
</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>
True
</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>
True
</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>
False
</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>
NDEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.optimization.level>
Optimize for size (-Os)
</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.OtherFlags>
-fdata-sections
</avrgcc.compiler.optimization.OtherFlags>
<avrgcc.compiler.optimization.PackStructureMembers>
True
</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>
True
</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.miscellaneous.OtherFlags>
-std=gnu99 -fno-strict-aliasing -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -mrelax
</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>
NDEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.optimization.level>
Optimize for size (-Os)
</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>
True
</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.warnings.AllWarnings>
True
</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>
libm
</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>
%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\include
</Value>
<Value>
../common/applications/user_application/user_board/config
</Value>
<Value>
../src/config
</Value>
<Value>
../src
</Value>
<Value>
../src/ASF/common/boards/user_board
</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
</AvrGccCpp>
<avrgcc.common.Device>
-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\gcc\dev\atmega328p"
</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>
True
</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>
True
</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>
True
</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>
True
</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>
False
</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>
NDEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.optimization.level>
Optimize for size (-Os)
</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.OtherFlags>
-fdata-sections
</avrgcc.compiler.optimization.OtherFlags>
<avrgcc.compiler.optimization.PackStructureMembers>
True
</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>
True
</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.miscellaneous.OtherFlags>
-std=gnu99 -fno-strict-aliasing -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -mrelax
</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>
NDEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.optimization.level>
Optimize for size (-Os)
</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>
True
</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.warnings.AllWarnings>
True
</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>
libm
</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>
%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\include
</Value>
<Value>
../common/applications/user_application/user_board/config
</Value>
<Value>
../src/config
</Value>
<Value>
../src
</Value>
<Value>
../src/ASF/common/boards/user_board
</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)' == 'Debug' "
>
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>
-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\gcc\dev\atmega328p"
</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>
True
</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>
True
</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>
True
</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>
True
</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>
False
</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>
DEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.optimization.level>
Optimize (-O1)
</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.OtherFlags>
-fdata-sections
</avrgcc.compiler.optimization.OtherFlags>
<avrgcc.compiler.optimization.PackStructureMembers>
True
</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>
Maximum (-g3)
</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>
True
</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.miscellaneous.OtherFlags>
-std=gnu99 -fno-strict-aliasing -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -mrelax
</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>
DEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.optimization.level>
Optimize (-O1)
</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>
True
</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.optimization.DebugLevel>
Default (-g2)
</avrgcccpp.compiler.optimization.DebugLevel>
<avrgcccpp.compiler.warnings.AllWarnings>
True
</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>
libm
</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>
%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\include
</Value>
<Value>
../common/applications/user_application/user_board/config
</Value>
<Value>
../src/config
</Value>
<Value>
../src
</Value>
<Value>
../src/ASF/common/boards/user_board
</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
<avrgcccpp.assembler.debugging.DebugLevel>
Default (-Wa,-g)
</avrgcccpp.assembler.debugging.DebugLevel>
</AvrGccCpp>
<avrgcc.common.Device>
-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\gcc\dev\atmega328p"
</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>
True
</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>
True
</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>
True
</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>
True
</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>
False
</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>
DEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.optimization.level>
Optimize (-O1)
</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.OtherFlags>
-fdata-sections
</avrgcc.compiler.optimization.OtherFlags>
<avrgcc.compiler.optimization.PackStructureMembers>
True
</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>
Maximum (-g3)
</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>
True
</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.compiler.miscellaneous.OtherFlags>
-std=gnu99 -fno-strict-aliasing -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -mrelax
</avrgcc.compiler.miscellaneous.OtherFlags>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
True
</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>
DEBUG
</Value>
<Value>
F_CPU=8000000UL
</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.optimization.level>
Optimize (-O1)
</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>
True
</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
True
</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.optimization.DebugLevel>
Default (-g2)
</avrgcccpp.compiler.optimization.DebugLevel>
<avrgcccpp.compiler.warnings.AllWarnings>
True
</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>
libm
</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>
%24(PackRepoDir)\atmel\ATmega_DFP\1.0.98\include
</Value>
<Value>
../common/applications/user_application/user_board/config
</Value>
<Value>
../src/config
</Value>
<Value>
../src
</Value>
<Value>
../src/ASF/common/boards/user_board
</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
<avrgcccpp.assembler.debugging.DebugLevel>
Default (-Wa,-g)
</avrgcccpp.assembler.debugging.DebugLevel>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
...
...
Software/Firmware/Binaeruhr/Binaeruhr/lib/CLOCK.cpp
View file @
bebfc2eb
/*
* C
LOCK
.cpp
* C
lock
.cpp
*
* Created: 11.04.2016 17:48:30
* Author: alex
*/
#include "C
LOCK
.h"
#include "C
lock
.h"
// default constructor
C
LOCK
::
CLOCK
()
C
lock
::
Clock
()
{
}
//C
LOCK
}
//C
lock
void
C
LOCK
::
update
()
{
void
C
lock
::
update
()
{
ds1307
.
obtainTime
();
shiftTime
(
ds1307
.
getHour
(
false
),
ds1307
.
getMinute
(
false
),
ds1307
.
getSecond
(
false
));
}
void
C
LOCK
::
shiftTime
(
uint8_t
hour
,
uint8_t
minute
,
uint8_t
second
)
{
void
C
lock
::
shiftTime
(
uint8_t
hour
,
uint8_t
minute
,
uint8_t
second
)
{
shiftr
.
shift
(
hour
);
shiftr
.
shift
(
minute
);
shiftr
.
shift
(
second
,
true
);
}
void
C
LOCK
::
setTime
(
uint8_t
day
,
uint8_t
month
,
uint8_t
year
,
uint8_t
hour
,
uint8_t
minute
,
uint8_t
second
)
{
void
C
lock
::
setTime
(
uint8_t
day
,
uint8_t
month
,
uint8_t
year
,
uint8_t
hour
,
uint8_t
minute
,
uint8_t
second
)
{
ds1307
.
setTime
(
day
,
month
,
year
,
hour
,
minute
,
second
);
}
// default destructor
C
LOCK
::~
CLOCK
()
C
lock
::~
Clock
()
{
}
//~C
LOCK
}
//~C
lock
Software/Firmware/Binaeruhr/Binaeruhr/lib/CLOCK.h
View file @
bebfc2eb
/*
* C
LOCK
.h
* C
lock
.h
*
* Created: 11.04.2016 17:48:30
* Author: alex
...
...
@@ -10,29 +10,29 @@
#define __CLOCK_H__
#include "DS1307.h"
#include "S
HIFTREGISTER
.h"
#include "S
hiftregister
.h"
class
C
LOCK
class
C
lock
{
//variables
public:
protected:
private:
DS1307
ds1307
;
S
HIFTREGISTER
shiftr
;
S
hiftregister
shiftr
;
//functions
public:
C
LOCK
();
~
C
LOCK
();
C
lock
();
~
C
lock
();
void
update
();
void
setTime
(
uint8_t
day
,
uint8_t
month
,
uint8_t
year
,
uint8_t
hour
,
uint8_t
minute
,
uint8_t
second
);
protected:
private:
C
LOCK
(
const
C
LOCK
&
c
);
C
LOCK
&
operator
=
(
const
C
LOCK
&
c
);
C
lock
(
const
C
lock
&
c
);
C
lock
&
operator
=
(
const
C
lock
&
c
);
void
shiftTime
(
uint8_t
hour
,
uint8_t
minute
,
uint8_t
second
);
};
//C
LOCK
};
//C
lock
#endif //__CLOCK_H__
Software/Firmware/Binaeruhr/Binaeruhr/lib/SHIFTREGISTER.cpp
View file @
bebfc2eb
/*
* S
HIFTREGISTER
.cpp
* S
hiftregister
.cpp
*
* Created: 03.04.2016 11:07:20
* Author: alex
*/
#include "S
HIFTREGISTER
.h"
#include "S
hiftregister
.h"
// default constructor
SHIFTREGISTER
::
SHIFTREGISTER
()
{
Shiftregister
::
Shiftregister
()
{
SHIFT_DDR
|=
(
(
1
<<
SHIFT_SCK
)
|
(
1
<<
SHIFT_RCK
)
|
(
1
<<
SHIFT_DATA
)
);
// Make that pins output
}
//S
HIFTREGISTER
}
//S
hiftregister
// Sends one C-clock-wide high pulse on SCK-clock-line (Shift-clock)
// --> next bit can be shifted in
void
S
HIFTREGISTER
::
pulse
()
{
void
S
hiftregister
::
pulse
()
{
SHIFT_PORT
|=
(
1
<<
SHIFT_SCK
);
SHIFT_PORT
&=
(
~
(
1
<<
SHIFT_SCK
));
}
// Sends one C-clock-wide high pulse on RCK-clock-line (Latch-clock)
// --> all shifted bits are applied for the output
void
S
HIFTREGISTER
::
latch
()
{
void
S
hiftregister
::
latch
()
{
SHIFT_PORT
|=
(
1
<<
SHIFT_RCK
);
SHIFT_PORT
&=
(
~
(
1
<<
SHIFT_RCK
));
}
// shift the data MSB-first
void
S
HIFTREGISTER
::
shift
(
uint8_t
data
,
bool
_latch
)
{
void
S
hiftregister
::
shift
(
uint8_t
data
,
bool
_latch
)
{
for
(
uint8_t
i
=
0
;
i
<
8
;
i
++
)
{
if
(
data
&
0x80
)
SHIFT_DataHigh
();
//check whether or not the MSB is set
else
SHIFT_DataLow
();
...
...
@@ -42,6 +41,6 @@ void SHIFTREGISTER::shift(uint8_t data, bool _latch) {
}
// default destructor
S
HIFTREGISTER
::~
SHIFTREGISTER
()
S
hiftregister
::~
Shiftregister
()
{
}
//~SHIFTREGISTER
\ No newline at end of file
}
//~Shiftregister
\ No newline at end of file
Software/Firmware/Binaeruhr/Binaeruhr/lib/SHIFTREGISTER.h
View file @
bebfc2eb
/*
* S
HIFTREGISTER
.h
* S
hiftregister
.h
*
* Created: 03.04.2016 11:07:20
* Author: alex
...
...
@@ -13,33 +13,32 @@
// Defines
#define SHIFT_PORT PORTD
#define SHIFT_DDR DDRD
#define SHIFT_DATA PD5 //Data pin (DS) pin location
#define SHIFT_SCK PD6 //Shift Clock (SH_CP) pin location
#define SHIFT_RCK PD7 //Store Clock (ST_CP) pin location
#define SHIFT_DATA PD5 //
Data pin (DS) pin location
#define SHIFT_SCK PD6 //
Shift Clock (SH_CP) pin location
#define SHIFT_RCK PD7 //
Store Clock (ST_CP) pin location
// change data lines
#define SHIFT_DataHigh() (SHIFT_PORT |= (1<<SHIFT_DATA))
#define SHIFT_DataLow() (SHIFT_PORT &= (~(1<<SHIFT_DATA)))
class
SHIFTREGISTER
{
//variables
class
Shiftregister
{
// variables
public:
protected:
private:
//functions
//
functions
public:
S
HIFTREGISTER
();
~
S
HIFTREGISTER
();
S
hiftregister
();
~
S
hiftregister
();
void
shift
(
uint8_t
data
,
bool
_latch
=
false
);
protected:
private:
S
HIFTREGISTER
(
const
SHIFTREGISTER
&
c
);
S
HIFTREGISTER
&
operator
=
(
const
S
HIFTREGISTER
&
c
);
S
hiftregister
(
const
Shiftregister
&
c
);
S
hiftregister
&
operator
=
(
const
S
hiftregister
&
c
);
void
pulse
();
void
latch
();
};
//S
HIFTREGISTER
};
//S
hiftregister
#endif //__SHIFTREGISTER_H__
Software/Firmware/Binaeruhr/Binaeruhr/lib/UART.cpp
View file @
bebfc2eb
/*
* UART.cpp
*
* Created: 22.01.2015 22:40:20
* Author: Alexander
*/
/** \file Uart.cpp
* Implementation of the UART
* Abstraction Layer of the Hardware
*
* \date 22.01.2015 22:40:20
* \author Alexander Detsch
* \version 1.5
*/
#include "UART.h"
// DO NOT CHANGE DIRECTLY!
volatile
bool
uartStrComplete
=
0
;
// 1 .. completely received string
volatile
uint8_t
uartStrCount
=
0
;
volatile
char
uartString
[
UART_MAXSTRLEN
+
1
]
=
""
;
#include "Uart.h"
// default constructor
UART
::
UART
(
uint16_t
baudrate
)
{
UBRR0L
=
F_CPU
/
baudrate
/
16
-
1
;
// calculation of the init-value from system clock and baudrate
UCSR0B
|=
(
1
<<
TXEN0
)
|
(
1
<<
RXEN0
)
|
(
1
<<
RXCIE0
);
// Enable TX, RX, RX-Interrupt
UCSR0C
|=
(
1
<<
UCSZ00
)
|
(
1
<<
UCSZ01
);
// Set frame format to 8N1
char
Uart
::
receivedUartString
[
UART_MAXSTRLEN
+
1
]
=
{};
volatile
bool
Uart
::
uartStrComplete
=
false
;
volatile
uint8_t
Uart
::
uartStrCount
=
0
;
volatile
uint8_t
Uart
::
uartString
[
UART_MAXSTRLEN
+
1
]
=
{};
Uart
::
Uart
()
{
}
//Uart
// default destructor
Uart
::~
Uart
()
{
}
//~Uart
void
Uart
::
begin
(
uint32_t
baudrate
,
uint8_t
config
)
{
cli
();
// set baudrate and asynchronous double speed
uint16_t
baud
=
(
F_CPU
/
4
/
baudrate
-
1
)
/
2
;
UBRR0H
=
baud
>>
8
;
UBRR0L
=
baud
;
UCSR0A
|=
(
1
<<
U2X0
);
/*
// set baudrate and asynchronous normal speed
uint16_t baud = (F_CPU / 8 / baudrate - 1) / 2;
UBRR0H = baud >> 8;
UBRR0L = baud;
*/
UCSR0B
|=
(
1
<<
TXEN0
)
|
(
1
<<
RXEN0
)
|
(
1
<<
RXCIE0
);
// Enable TX, RX, RX-Interrupt
UCSR0C
=
config
;
// set mode of the UART such as 8N1, 8N2, ...
receivedUartString
[
0
]
=
0
;
// Flush Receive-Buffer (entfernen evtl. vorhandener ungültiger Werte)
do
{
UDR0
;
}
while
(
UCSR0A
&
(
1
<<
RXC0
));
sei
();
}
//UART
}
void
Uart
::
begin
(
uint32_t
baudrate
)
{
begin
(
baudrate
,
SERIAL_8N1
);
// use 8N1 as standard
}
/**
Send a single char directly over the UART
Wait until the transmit buffer is empty and then send the byte.
@param data byte that should be transmitted
@ingroup physTransmit
*/
void
Uart
::
putChar
(
char
data
)
{
while
(
!
(
UCSR0A
&
(
1
<<
UDRE0
)));
// wait until UDR empty USR = UCSRA
UDR0
=
data
;
// send
}
/**
Send a single byte directly over the UART
Wait until the transmit buffer is empty and then send the byte.
UART
::
UART
()
{}
@param data byte that should be transmitted
@ingroup physTransmit
*/
void
Uart
::
putByte
(
uint8_t
data
)
{
while
(
!
(
UCSR0A
&
(
1
<<
UDRE0
)));
// wait until UDR empty USR = UCSRA
UDR0
=
data
;
// send
}
void
UART
::
putChar
(
char
data
)
{
/**
Empty the receive buffer, reset the data to null
@ingroup transmit
*/
void
Uart
::
empty
()
{
uartStrCount
=
0
;
uartStrComplete
=
false
;
for
(
uint8_t
i
=
0
;
i
<
UART_MAXSTRLEN
;
i
++
)
{
receivedUartString
[
i
]
=
0
;
uartString
[
i
]
=
0
;
}
}
/**
Empty the transmit buffer
Wait until the transmit buffer is empty and then returns.
@ingroup physTransmit
*/
void
Uart
::
flush
()
{
while
(
!
(
UCSR0A
&
(
1
<<
UDRE0
)));
// wait until UDR empty USR = UCSRA
UDR0
=
data
;
// send
}
}
/**
Send a bunch of chars over the UART.
Sends all passed chars in the array one after another
void
UART
::
printChar
(
char
const
buffer
[])
{
@param buffer char array that should be transmitted
@ingroup transmit
*/
void
Uart
::
printChar
(
char
const
buffer
[])
{
for
(
uint8_t
i
=
0
;
buffer
[
i
]
!=
0
;
i
++
)
putChar
(
buffer
[
i
]);
putChar
(
buffer
[
i
]);
}
void
UART
::
print
(
char
const
*
szFormat
,
...)
{
char
floatArray
[
50
];
/**
Send a formatted string over the UART
All format options for printf can be used.
@param string String that should be send
@param formatOptions all format options known from standard-printf
@ingroup transmit
*/
void
Uart
::
print
(
char
const
*
szFormat
,
...)
{
char
data
[
UART_MAX_SEND_LENGTH
];
va_list
pArgs
;
va_start
(
pArgs
,
szFormat
);
vsnprintf
(
floatArray
,
sizeof
(
floatArray
)
-
1
,
szFormat
,
pArgs
);
vsnprintf
(
data
,
sizeof
(
data
)
-
1
,
szFormat
,
pArgs
);
va_end
(
pArgs
);
printChar
(
floatArray
);
printChar
(
data
);
}
// just a f..ing bunch of wrappers. Nothing special.
void
UART
::
print
(
float
number
)
{
/**
@name Print Numbers in different flavours.
No CR at the end of the transmission.
@param number number that should be formatted and transmitted.
@ingroup print
*/
//@{
///Print float
void
Uart
::
print
(
float
number
)
{
print
(
"%f"
,
(
double
)
number
);
}
void
UART
::
print
(
double
number
)
{
/**
@brief Print double
@param number number that should be formatted and transmitted.
*/
void
Uart
::
print
(
double
number
)
{
print
(
"%f"
,
number
);
}
void
UART
::
print
(
uint32_t
number
)
{
/**
@brief Print 32-bit unsigned Integer
@param number number that should be formatted and transmitted.
*/
void
Uart
::