From e8c784a9502bbaa8d3c47b2fc60884311632d968 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Thu, 25 May 2017 02:40:18 +0200 Subject: Simple counter (in seconds) --- .clang-format | 5 +++ .ycm_extra_conf.py | 26 ++++++++++++ Makefile | 17 ++++++-- main.c | 118 +++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 136 insertions(+), 30 deletions(-) create mode 100644 .clang-format create mode 100644 .ycm_extra_conf.py diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b8ecd2e --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BasedOnStyle: Webkit +IndentWidth: 2 +BreakBeforeBraces: Allman +AllowShortIfStatementsOnASingleLine: false +ColumnLimit: 120 diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py new file mode 100644 index 0000000..42834fb --- /dev/null +++ b/.ycm_extra_conf.py @@ -0,0 +1,26 @@ +import os +import ycm_core + +def FlagsForFile( filename, **kwargs ): + return { + 'flags': [ + '-Wall', + '-Wextra', + '-Werror', + '-Wno-long-long', + '-Wno-variadic-macros', + '-fexceptions', + '-ferror-limit=10000', + '-DNDEBUG', + '-std=c99', + '-x', 'c', + '-D_GNU_SOURCE', + '-D__AVR_ATtiny85__', + '-D__AVR__', + '-I.', + '-I', '/usr/avr/include/' + ], + 'do_cache': True, + } + +# vim:set et sw=2 ts=2 tw=120: diff --git a/Makefile b/Makefile index e63d2c0..e81f5a1 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,17 @@ -FLAGS=-Wall -I/usr/lib/gcc/avr/6.3.0/plugin/include/ -I/usr/avr/include -mmcu=attiny13 -O3 -DF_CPU=1200000 +FLAGS=-Wall -O5 -Werror +FLAGS+=-mmcu=attiny85 +FLAGS+=-D__AVR_ATtiny85__=1 +# FLAGS+=-DF_CPU=120000UL +# FLAGS+=-DF_CPU=960000UL +FLAGS+=-DF_CPU=800000UL +FLAGS+=-I inc/int/ +FLAGS+=-I/usr/lib/gcc/avr/6.3.0/plugin/include/ +FLAGS+=-I/usr/avr/include + +program: all + avrdude -V -B100 -p t85 -c avrisp2 -P usb -U flash:w:main.hex all: - avr-gcc $(FLAGS) -o main.elf main.c + avr-gcc $(FLAGS) -o main.elf main.c inc/int/dcf77.c avr-objcopy -j .text -j .data -O ihex main.elf main.hex -program: all - avrdude -B100 -p t85 -c avrisp2 -P usb -U flash:w:main.hex diff --git a/main.c b/main.c index 2b5753d..2dd8058 100644 --- a/main.c +++ b/main.c @@ -1,15 +1,12 @@ // vim:set et sw=2 ts=2 tw=120: -#define __AVR_ATtiny85__ +#include +#include #include -#include // (1) +#include -#ifndef F_CPU -#warning "F_CPU war noch nicht definiert, wird nun mit 3686400 definiert" -#define F_CPU 1000000UL -#endif +#include "inc/int/dcf77.h" -#include -#include +#define CTC_MATCH_OVERFLOW ((F_CPU / 1000) / 8) // set bit static inline void BIT_SET(volatile uint8_t* target, uint8_t bit) __attribute__((always_inline)); @@ -19,52 +16,121 @@ static inline void BIT_SET(volatile uint8_t* target, uint8_t bit) { *target |= ( static inline void BIT_CLEAR(volatile uint8_t* target, uint8_t bit) __attribute__((always_inline)); static inline void BIT_CLEAR(volatile uint8_t* target, uint8_t bit) { *target &= ~(1 << bit); }; + +/* + * + * PB2 : connected to ShiftClock on Port 11 + * PB3 : connected to MemoryClock on Port 12 (shows content of memory) + * PB4 (PIN3) : connected to SERIAL_IN on pin 14 + * + */ + void pulse_sck() { PORTB |= (1 << PB2); - _delay_ms(10); // Eine Sekunde +/-1/10000 Sekunde warten... PORTB ^= (1 << PB2); + } void print_data(uint16_t data) { - BIT_CLEAR(&PORTB, PB4); - _delay_ms(50); - BIT_SET(&PORTB, PB4); + //BIT_CLEAR(&PORTB, PB4); + //BIT_SET(&PORTB, PB4); for (uint16_t i = 0; i < 16; i++) { - data & 0x1 << i ? BIT_SET(&PORTB, PB4) : BIT_CLEAR(&PORTB, PB4); + data & 0x1 << i + ? BIT_SET(&PORTB, PB4) + : BIT_CLEAR(&PORTB, PB4); pulse_sck(); } - + //BIT_CLEAR(&PORTB, PB4); + // pulse_sck(); BIT_CLEAR(&PORTB, PB3); - _delay_ms(50); BIT_SET(&PORTB, PB3); + } int main(void) { - DDRB = 0xFF; BIT_CLEAR(&PORTB, PB5); - _delay_ms(200); + _delay_ms(20); BIT_SET(&PORTB, PB5); BIT_CLEAR(&PORTB, PB5); - _delay_ms(200); + _delay_ms(20); BIT_SET(&PORTB, PB5); + + + // make all pins output pins... + DDRB = 0xFF; + DDRB &= ~(1 << PB0); // makes PB0 an input pin (INT0) + PORTB |= (1 << PB0); // activate input resistor + + // activate dcf77-receiver... + PORTB &= (1 << PB1); // sets PB1 to low + _delay_ms(20); + PORTB &= ~(1 << PB1); // sets PB1 to low + + + cli(); + + /* + GIMSK |= (1<