2 #include <avr/interrupt.h>
6 //********************************************************************//
8 typedef unsigned char byte;
15 // offset is number of alphas (0.08ms)
17 const rf_bit_t zero_bit[] = { { 4, 1 },
23 const rf_bit_t one_bit[] = { { 12, 1 },
29 const rf_bit_t float_bit[] = { { 4, 1 },
35 const rf_bit_t sync_bit[] = { { 4, 1 },
39 typedef enum { ZERO = 0, ONE , FLOAT , SYNC } adbit_t;
40 typedef byte ad_bit_t;
42 typedef ad_bit_t word_t[WORD_LEN];
44 const rf_bit_t* bit_defs[] = { zero_bit, one_bit, float_bit, sync_bit };
50 const ad_bit_t* current_word;
51 byte volatile frame_finished = 1;
75 const word_t words[] = {
76 { ZERO, ZERO, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // A1_ON
77 { ZERO, ZERO, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // A1_OFF
78 { ZERO, ZERO, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // A2_ON
79 { ZERO, ZERO, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // A2_OFF
81 { FLOAT, ZERO, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // B1_ON
82 { FLOAT, ZERO, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // B1_OFF
83 { FLOAT, ZERO, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // B2_ON
84 { FLOAT, ZERO, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // B2_OFF
86 { ZERO, FLOAT, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // C1_ON
87 { ZERO, FLOAT, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // C1_OFF
88 { ZERO, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // C2_ON
89 { ZERO, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // C2_OFF
91 { FLOAT, FLOAT, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // D1_ON
92 { FLOAT, FLOAT, FLOAT, FLOAT, ZERO, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC }, // D1_OFF
93 { FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC }, // D2_ON
94 { FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, SYNC } // D2_OFF
98 //********************************************************************//
103 TCCR1A = 0; // prescaler 1:8, WGM = 4 (CTC)
104 TCCR1B = 1<<WGM12 | 1<<CS11; //
105 OCR1A = 159; // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
106 // OCR1A = 207; // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
107 TCNT1 = 0; // reseting timer
108 TIMSK1 = 1<<OCIE1A; // enable Interrupt
111 void stop_timer() // stop the timer
114 TCCR1B = 0; // no clock source
115 TIMSK1 = 0; // disable timer interrupt
126 ISR(TIMER1_COMPA_vect)
128 byte sample = digitalRead(RF433_PIN);
129 if (last_sample!=sample && sample==HIGH)
131 if ( rf433_lo_cnt > 2 && rf433_lo_cnt<6 && rf433_hi_cnt>10 && rf433_hi_cnt < 14)
133 rf433_data.uint32<<=1;
134 rf433_data.uint32|=1;
136 } else if (rf433_hi_cnt > 2 && rf433_hi_cnt<6 && rf433_lo_cnt>10 && rf433_lo_cnt < 14) {
137 rf433_data.uint32<<=1;
139 } else if (rf433_hi_cnt > 2 && rf433_hi_cnt<6 && rf433_lo_cnt>120 && rf433_lo_cnt < 128 && valid >=24) {
140 //rf433_data.uint8[3]=0;
141 //Serial.print(rf433_data.uint32);
142 Serial.print(rf433_data.uint8[0],BYTE);
143 Serial.print(rf433_data.uint8[1],BYTE);
144 Serial.print(rf433_data.uint8[2],BYTE);
145 //Serial.print(rf433_data.uint8[3],BYTE);
160 //unsigned long wm_start_[3]={0,0,0};
161 //bool wait_millis(unsigned long *start_time, unsigned long ms)
165 // else if (*start_time > 0)
167 // if (millis() < *start_time || millis() > (*start_time) + ms)
177 // *start_time=millis();
182 //********************************************************************//
186 pinMode(RF433_PIN, INPUT); // set pin to input
187 digitalWrite(RF433_PIN, LOW); // turn of pullup resistors
190 // Serial.println("starting timer");