aboutsummaryrefslogtreecommitdiff
path: root/software/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/main.c')
-rw-r--r--software/main.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/software/main.c b/software/main.c
new file mode 100644
index 0000000..9e2cb5d
--- /dev/null
+++ b/software/main.c
@@ -0,0 +1,129 @@
1// vim:set et sw=2 ts=2 tw=120:
2#include <stdint.h>
3#include <avr/io.h>
4#include <avr/interrupt.h>
5#include <util/delay.h>
6
7#include "inc/int/dcf77.h"
8
9#define CTC_MATCH_OVERFLOW ((F_CPU / 1000) / 8)
10
11// set bit
12static inline void BIT_SET(volatile uint8_t* target, uint8_t bit) __attribute__((always_inline));
13static inline void BIT_SET(volatile uint8_t* target, uint8_t bit) { *target |= (1 << bit); };
14
15// set clear
16static inline void BIT_CLEAR(volatile uint8_t* target, uint8_t bit) __attribute__((always_inline));
17static inline void BIT_CLEAR(volatile uint8_t* target, uint8_t bit) { *target &= ~(1 << bit); };
18
19
20/*
21 *
22 * PB2 : connected to ShiftClock on Port 11
23 * PB3 : connected to MemoryClock on Port 12 (shows content of memory)
24 * PB4 (PIN3) : connected to SERIAL_IN on pin 14
25 *
26 */
27
28void print_data(uint16_t data)
29{
30 BIT_CLEAR(&PORTB, PB3);
31 for (char i = 0; i < 16; i++)
32 {
33 data & 0x1 << i
34 ? BIT_SET(&PORTB, PB4)
35 : BIT_CLEAR(&PORTB, PB4);
36 // pulse sck...
37 BIT_SET(&PORTB, PB2);
38 BIT_CLEAR(&PORTB, PB2);
39 }
40 BIT_SET(&PORTB, PB3);
41}
42
43int main(void)
44{
45
46 BIT_CLEAR(&PORTB, PB5);
47 _delay_ms(20);
48 BIT_SET(&PORTB, PB5);
49 BIT_CLEAR(&PORTB, PB5);
50 _delay_ms(20);
51 BIT_SET(&PORTB, PB5);
52
53
54
55 // make all pins output pins...
56 // DDRB = 0xFF;
57 DDRB = 0b11111110;
58 PORTB |= 1<<PB0; // activate pullup
59 PORTB |= 1<<PB1; // activate receiver
60 PORTB &= ~(1<<PB1);
61
62 // DDRB &= ~(1 << PB0); // makes PB0 an input pin (INT0)
63 // PORTB |= (1 << PB0); // activate input resistor
64
65 // activate dcf77-receiver...
66 // PORTB &= (1 << PB1); // sets PB1 to low
67 // _delay_ms(20);
68 // PORTB &= ~(1 << PB1); // sets PB1 to low
69
70
71 cli();
72
73 GIMSK |= (1<<INT0); // External Interrupt Request 0 Enable
74 GIMSK |= (1<<PCIE); // Pin Change Interrupt Enable
75
76 // MCU Control Register (controls CPU-behaviours like interrupts & sleepmode)
77 // MCUCR |= ~(1<<ISC01) | (1<<ISC00); // any logical change generates interrupt
78 PCMSK |= (1<<PCINT0);
79 // INT0_CONTROL = INT0_RISING_EDGE; // going to toggle int0-behaviour
80
81 TCCR0A |= (1 << WGM01); // CTC mode
82 // TCCR0B |= (1 << CS00);
83 TCCR0B |= (1 << CS01); // Prescaler 8
84 // TCCR0B |= (1 << CS02); // Prescaler 256
85 // OCR0A |= (1 << WGM01); // CTC mode
86
87 // OCR0A = 149;
88 OCR0A = 125;
89 // OCR0A = CTC_MATCH_OVERFLOW;
90 TIMSK |= (1 << OCIE0A); // if you want interrupt
91
92 sei();
93
94 for(uint8_t i=0; i<16; i++)
95 {
96 print_data(3<<i);
97 _delay_ms(5);
98 }
99
100 while (1)
101 {
102 //print_data(lastinterval<<1 | (PINB & PB0));
103
104 print_data(
105 (uint16_t) 0
106 | ((uint16_t) (PINB & 0x0001))<<15
107 | t_current.h<<8
108 | t_current.m
109 );
110 // print_data(interval | ((PINB & PB0) == 1 ? 2 : 0));
111 //print_data(PINB);
112 }
113 return 0;
114}
115
116
117/*
118for(uint16_t hour=0; hour<24; hour++)
119 for(uint16_t minute=0; minute<60; minute++)
120 for (uint16_t second = 1; second < 60; second++)
121 {
122 // clear register (reset)
123 // print_data(hour<< 12 | minute << 6 | second);
124 // print_data((int64_t) dcf77);
125 // dcf77[dcf77_bit].bit == 1
126 // ? print_data(0xFFFF)
127 // : print_data(0x0000);
128 }A
129*/
..