aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinc/int/dcf77.c58
-rwxr-xr-xinc/int/dcf77.h15
-rw-r--r--main.c42
3 files changed, 48 insertions, 67 deletions
diff --git a/inc/int/dcf77.c b/inc/int/dcf77.c
index 13af50d..31f1663 100755
--- a/inc/int/dcf77.c
+++ b/inc/int/dcf77.c
@@ -1,10 +1,14 @@
1// vim:set et sw=2 ts=2 tw=120: 1// vim:set et sw=2 ts=2 tw=120:
2#include "dcf77.h" 2#include "dcf77.h"
3 3
4// 7372800/a=10000
5// 115200 / a * x = 10000
6// 7372800/8/150
7
4// returns -1 on error 8// returns -1 on error
5unsigned char getBits(const DCF start, const char len) 9unsigned char getBits(const DCF start, const char len)
6{ 10{
7 static const unsigned char mult[] = {1, 2, 4, 8, 10, 20 ,40 ,80}; 11 static const unsigned char mult[] = {1, 2, 4, 8, 10, 20, 40, 80};
8 /// unsigned char p = 1; //parity 12 /// unsigned char p = 1; //parity
9 unsigned char r = 0; // retval 13 unsigned char r = 0; // retval
10 unsigned char i; 14 unsigned char i;
@@ -15,32 +19,13 @@ unsigned char getBits(const DCF start, const char len)
15 return r; 19 return r;
16} 20}
17 21
18void set_dcf_value()
19{
20 t_current.m = (getBits(DCF_MIN, 7)) - 1;
21 t_current.h = (getBits(DCF_HOUR, 6));
22 t_current.dd = (getBits(DCF_DAY, 6));
23 t_current.wd = (getBits(DCF_WEEKDAY, 3));
24 t_current.mm = (getBits(DCF_MONTH, 5));
25 t_current.yy = (getBits(DCF_YEAR, 8));
26}
27
28// 7372800/a=10000
29// 115200 / a * x = 10000
30// 7372800/8/150
31
32// interrupt service routine (ISR) for timer 0 A compare match 22// interrupt service routine (ISR) for timer 0 A compare match
33/*
34ISR(TIMER0A_COMP_vect) // called 10000 times per second (12000000/8/150)
35{
36
37}
38*/
39ISR(TIMER0_COMPB_vect) 23ISR(TIMER0_COMPB_vect)
40{ 24{
41 25
42} 26}
43 27
28// ISR(TIMER0A_COMP_vect)
44ISR(TIMER0_COMPA_vect) 29ISR(TIMER0_COMPA_vect)
45{ 30{
46 interval++; 31 interval++;
@@ -69,43 +54,42 @@ ISR(INT0_vect)
69 54
70ISR(PCINT0_vect) 55ISR(PCINT0_vect)
71{ 56{
72 interval = 1;
73 /// stdout_put_int(interval, uart_putc);
74 /// stdout_put_string("INT0 call\n", uart_putc);
75 // cli();
76
77 // if(INT0_CONTROL == INT0_RISING_EDGE) 57 // if(INT0_CONTROL == INT0_RISING_EDGE)
78 // if(MCUCR & (1<<ISC00)) 58 // if(MCUCR & (1<<ISC00))
79 // { 59 // {
80 if (interval > 1000 && interval < 2000) // 59th second - no rising edge at the beginning 60 if (interval > 1000 && interval < 2000) // 59th second - no rising edge at the beginning
81 { 61 {
82 /// if(dcf77_bit == 59) // check if every bit has been transfered 62 if(dcf77_bit == 59) // check if every bit has been transfered
83 // set_dcf_value(); // completely received- apply new time data 63 {
64 t_current.m = getBits(DCF_MIN, 7);
65 t_current.h = getBits(DCF_HOUR, 6);
66 t_current.dd = getBits(DCF_DAY, 6);
67 t_current.wd = getBits(DCF_WEEKDAY, 3);
68 t_current.mm = getBits(DCF_MONTH, 5);
69 t_current.yy = getBits(DCF_YEAR, 8);
70 }
84 71
85 // 59th second: synchronize with receiver... 72 // 59th second: synchronize with receiver...
86 TCNT0 = 0;
87 dcf77_bit = 0; 73 dcf77_bit = 0;
88 t_current.s = 0; 74 t_current.s = 0;
89 t_current.ms = 0; 75 t_current.ms = 0;
90 // t_current.us = 0; 76
91 // falling edge causes interrupt... 77 // falling edge causes interrupt...
92 // MCUCR &= ~(1 << ISC00);
93 // MCUCR |= (1 << ISC01);
94 // INT0_CONTROL = INT0_FALLING_EDGE; 78 // INT0_CONTROL = INT0_FALLING_EDGE;
95 } 79 }
96 else // INT0_FALLING_EDGE 80 else // INT0_FALLING_EDGE
97 { 81 {
98 dcf77[dcf77_bit++].bit = interval >= 200 ? 1 : 0; 82 if(interval > 50 && interval < 150)
83 dcf77[dcf77_bit++].bit = 0;
84 else if(interval > 150 && interval < 250)
85 dcf77[dcf77_bit++].bit = 1;
99 86
100 // rising edge causes interrupt... 87 // rising edge causes interrupt...
101 // MCUCR |= (1 << ISC00);
102 // MCUCR |= (1 << ISC01);
103 // INT0_CONTROL = INT0_RISING_EDGE; 88 // INT0_CONTROL = INT0_RISING_EDGE;
104 // interval = 0; // reset interval to count next interval
105 } 89 }
106 90
91 TCNT0 = 0;
107 interval = 0; 92 interval = 0;
108 // sei();
109} 93}
110 94
111/* 95/*
diff --git a/inc/int/dcf77.h b/inc/int/dcf77.h
index e47ca4e..2d79cdd 100755
--- a/inc/int/dcf77.h
+++ b/inc/int/dcf77.h
@@ -9,7 +9,6 @@
9 */ 9 */
10 #include <avr/io.h> 10 #include <avr/io.h>
11 #include <avr/interrupt.h> 11 #include <avr/interrupt.h>
12
13 #include <stdint.h> 12 #include <stdint.h>
14 13
15 #define INT0_CONTROL MCUCR 14 #define INT0_CONTROL MCUCR
@@ -26,14 +25,14 @@
26 25
27 typedef struct 26 typedef struct
28 { 27 {
29 uint16_t h ; // hour 28 uint16_t h; // hour
30 uint16_t m ; // minute 29 uint16_t m; // minute
31 uint16_t s ; // second 30 uint16_t s; // second
32 uint16_t ms; // milli second 31 uint16_t ms; // milli second
33 uint8_t yy; // year 32 uint8_t yy; // year
34 uint8_t mm; // month 33 uint8_t mm; // month
35 uint8_t dd; // day 34 uint8_t dd; // day
36 uint8_t wd; // weekday 35 uint8_t wd; // weekday
37 } Time; 36 } Time;
38 37
39 typedef enum 38 typedef enum
diff --git a/main.c b/main.c
index 5c8d616..6e86c36 100644
--- a/main.c
+++ b/main.c
@@ -84,7 +84,7 @@ int main(void)
84 // OCR0A |= (1 << WGM01); // CTC mode 84 // OCR0A |= (1 << WGM01); // CTC mode
85 85
86 // OCR0A = 149; 86 // OCR0A = 149;
87 OCR0A = 124; 87 OCR0A = 125;
88 // OCR0A = CTC_MATCH_OVERFLOW; 88 // OCR0A = CTC_MATCH_OVERFLOW;
89 TIMSK |= (1 << OCIE0A); // if you want interrupt 89 TIMSK |= (1 << OCIE0A); // if you want interrupt
90 90
@@ -92,27 +92,25 @@ int main(void)
92 92
93 while (1) 93 while (1)
94 { 94 {
95 // uint16_t t = 1; 95 //print_data(lastinterval<<1 | (PINB & PB0));
96 // for (uint16_t i=0; i<16; i++) 96 // uint16_t data = 0;
97 // { 97 // for(int i=0; i<16; i++)
98 // print_data(t_current.s); 98 // {
99 // uint16_t p = 0; 99 // if(i<4)
100 // for(int i=0; i<sizeof(t_current.s)*__CHAR_BIT__; i++) 100 // data |= (t_current.s & (1<<i));
101 // p |= t_current.s & (1<<i); 101 // else if(i <= 10)
102 102 // data |= t_current.m & (1<<(i-4));
103 print_data(t_current.s); 103 // else
104 // print_data(t_current.s<<10 | interval | ((PINB & PB0) == 1 ? 2 : 0)); 104 // data |= t_current.h & (1<<(i-11));
105 // t = t<<1; 105 // }
106 // } 106 // print_data(data);
107 // print_data(t_current.s); 107
108 108 print_data(
109 109 (uint64_t) 0
110 /* 110 | t_current.h<<8
111 print_data(0xFFFF); 111 | t_current.m);
112 _delay_ms(1000); 112 //print_data(interval | ((PINB & PB0) == 1 ? 2 : 0));
113 print_data(0x0000); 113 // print_data(PINB);
114 _delay_ms(1000);
115 */
116 } 114 }
117 return 0; 115 return 0;
118} 116}
..