dumping dart data to serial
[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 //INPUT PINS digitat 8-12 PINB
7 //INPUT PINS analog 0-4 PINC
8
9 #define RF433_PIN 10
10 //********************************************************************//
11
12 typedef unsigned char byte;
13
14 //********************************************************************//
15
16 void start_timer()
17 {
18   // timer 1: 2 ms
19   TCCR1A = 0;                    // prescaler 1:8, WGM = 4 (CTC)
20   TCCR1B = 1<<WGM12 | 1<<CS11;   // 
21   OCR1A = 159;        // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
22 //  OCR1A = 207;        // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
23   TCNT1 = 0;          // reseting timer
24   TIMSK1 = 1<<OCIE1A; // enable Interrupt
25 }
26
27 void stop_timer() // stop the timer
28 {
29   // timer1
30   TCCR1B = 0; // no clock source
31   TIMSK1 = 0; // disable timer interrupt
32 }
33
34 ISR(TIMER1_COMPA_vect)
35 {
36 // Serial.print('a');
37 }
38
39
40 void setup()
41 {
42 //  pinMode(RF433_PIN, INPUT);      // set pin to input
43 //  digitalWrite(RF433_PIN, LOW);  // turn of pullup resistors 
44   //Set Port as input
45   DDRB=0;
46 // disable pull up
47   PORTB=0;
48   DDRD = DDRD & 3;
49   PORTD= PORTD & 3;
50   DDRC=0;
51   PORTC=0;
52   Serial.begin(57600);
53   Serial.println("starting timer");
54 //  start_timer();
55 }
56
57 union union16 {
58   byte uint8[2];
59   uint16_t uint16;
60 }; 
61
62 //INPUT PINS digital 2-7 PIND
63 //INPUT PINS digitat 8-12 PINB
64 //INPUT PINS analog 0-4 PINC
65 void loop()
66 {
67 //  Serial.println("foo");
68 //  return;
69
70   union16 data;
71   data.uint8[0]=PIND;
72   data.uint16<<=3;
73   data.uint8[0]|= (PINC & B11111);
74   data.uint16<<=5; 
75   data.uint8[0]|= (PINB & B11111);
76   Serial.print(data.uint8[0]);
77   Serial.print(data.uint8[1]);
78 }