4c05548c056b8d3480438f10dde2e68cf9ed5298
[svn42.git] / dart / dart.pde
1 #include <avr/io.h>
2 #include <avr/interrupt.h>
3 #include <inttypes.h>
4
5 //INPUT PINS digital 2-7 PIND
6 #define PIND_MASK B11111100
7 //INPUT PINS digitat 8-12 PINB
8 #define PINB_MASK B00011111
9 //INPUT PINS analog 0-4 PINC
10 #define PINC_MASK B00011111
11
12 #define INPUT_SIG_PORTD B11000000
13 #define INPUT_SIG_PORTB B00011111
14 #define INPUT_SIG_PORTC B00010000
15 union union16 {
16   byte uint8[2];
17   uint16_t uint16;
18 }; 
19
20 union union32 {
21   byte uint8[4];
22   uint16_t uint16[2];
23   uint32_t uint32;
24 }; 
25
26
27 //********************************************************************//
28
29 typedef unsigned char byte;
30
31 //********************************************************************//
32 /*
33 void start_timer()
34 {
35   // timer 1: 2 ms
36   TCCR1A = 0;                    // prescaler 1:8, WGM = 4 (CTC)
37   TCCR1B = 1<<WGM12 | 1<<CS11;   // 
38   OCR1A = 159;        // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
39 //  OCR1A = 207;        // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
40   TCNT1 = 0;          // reseting timer
41   TIMSK1 = 1<<OCIE1A; // enable Interrupt
42 }
43
44 void stop_timer() // stop the timer
45 {
46   // timer1
47   TCCR1B = 0; // no clock source
48   TIMSK1 = 0; // disable timer interrupt
49 }
50 */
51 static void PCint(uint8_t port) {
52   Serial.println(port);
53   return;
54   union32 data;
55   data.uint32=0;
56   data.uint8[0]=PIND;
57   data.uint8[1]=PINC;
58   data.uint8[2]=PINB;
59   data.uint8[0]|= !PIND_MASK;
60   data.uint8[1]|= !PINC_MASK;
61   data.uint8[2]|= !PINB_MASK;
62   data.uint8[3]=0xff;
63   //PINS with signal:
64   //1
65   //3
66   //9
67   //14
68   //15
69   //21
70   //22
71   //23
72
73   for(int i=0;i<32; i++)
74   {
75     if (! (data.uint32 & 1 ))
76       Serial.println(i);
77     data.uint32>>=1;
78   }
79   //Serial.print(data.uint8[1]);
80 }
81
82
83
84 SIGNAL(PCINT0_vect) {
85   PCint(0);
86 }
87 SIGNAL(PCINT1_vect) {
88   PCint(1);
89 }
90 SIGNAL(PCINT2_vect) {
91   PCint(2);
92 }
93 void setup()
94 {
95 //  pinMode(RF433_PIN, INPUT);      // set pin to input
96 //  digitalWrite(RF433_PIN, LOW);  // turn of pullup resistors 
97   //Set Port as input
98   DDRB=0;
99 // disable pull up
100   PORTB=0;
101   DDRD = DDRD & 3;
102   PORTD= PORTD & 3;
103
104   DDRC=0;
105   PORTC=0;
106   Serial.begin(57600);
107   //Serial.println("starting timer");
108   PCMSK0=PINB_MASK & INPUT_SIG_PORTB;
109   PCMSK1=PINC_MASK & INPUT_SIG_PORTC;
110   PCMSK2=PIND_MASK & INPUT_SIG_PORTD;
111   PCICR|= B111;
112
113 //  start_timer();
114 }
115
116
117 //INPUT PINS digital 2-7 PIND
118 //INPUT PINS digitat 8-12 PINB
119 //INPUT PINS analog 0-4 PINC
120 void loop()
121 {
122 //  Serial.Serial.println("foo");
123 //  return;
124
125
126 }