merge

Mon, 28 Nov 2011 11:24:00 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Mon, 28 Nov 2011 11:24:00 +0100
changeset 18
cc2274b92647
parent 17
9e6feafc19e1 (diff)
parent 16
0250ceddee1b (current diff)
child 19
40a309c9c135

merge

--- a/receiver/main.c	Sun Nov 27 20:11:42 2011 +0100
+++ b/receiver/main.c	Mon Nov 28 11:24:00 2011 +0100
@@ -18,6 +18,33 @@
 // PD2 / PD3 = INT0 / INT1
 // connect IR receiver to these pins to measure frequencies
 
+volatile uint8_t car0, car1;
+uint8_t car_tmp0, car_tmp1, car_count0, car_count1, car_buffer0, car_buffer1;
+#define CARDETECT_CYCLES 2
+ISR ( TIMER0_OVF_vect ) {
+    // divides f_cpu by 256
+    // Interrupt every 32µs
+
+    if ( (PIN(PORTD) & _BV(PD2)) == 0) {
+        car_tmp0++;
+    } else {
+        // return car ID length
+        if (car_tmp0 != 0) {
+            car_count0++;
+            car_buffer0 += car_tmp0;
+            if (car_count0 == CARDETECT_CYCLES) {
+                car_buffer0 = (car_buffer0) / CARDETECT_CYCLES;
+                if (car_buffer0 == car_tmp0) car0 = car_tmp0;
+                //car0 = car_buffer0;
+                car_buffer0 = 0;
+                car_count0 = 0;
+            }
+            car_tmp0 = 0;
+        }
+    }
+
+}
+
 
 uint8_t get_car(uint8_t pin) {
     uint8_t i=0xff;
@@ -50,19 +77,33 @@
 {
     uint16_t i;
     unsigned char s[30];
+    
+    // initialize timer0 for IR signal detection
+    TCCR0 = _BV(CS00); // system clock, no prescaling
+    TIMSK = _BV(TOIE0);
 
     RS232_init(); // initialize RS232 interface
     RS232_puts_p(PSTR("Car ID Scanner v0.1\n"));
-
+    sei();
+    
     while (1) {
         // main loop
 
+/*
         i = get_car(_BV(PD2));
         if (i > 0) {
             itoa ( i , s, 10);
             RS232_puts(s);
             RS232_putc('\n');
         }
+*/
+
+        if (car0 > 0) {
+            itoa ( car0 , s, 10);
+            car0 = 0;
+            RS232_puts(s);
+            RS232_putc('\n');
+        }
 
     } // main loop end
 };

mercurial