projects
/
svn42.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rixed dxf logo
[svn42.git]
/
dart
/
dart.pde
diff --git
a/dart/dart.pde
b/dart/dart.pde
index
03bc643
..
6819665
100644
(file)
--- a/
dart/dart.pde
+++ b/
dart/dart.pde
@@
-2,6
+2,8
@@
#include <avr/interrupt.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <inttypes.h>
+//Player+Handycap BTN analog 5
+#define PLAYER_SIG_PORTC B00100000
//INPUT PINS digital 2-7 PIND
#define PIND_MASK B11111100
//INPUT PINS digitat 8-12 PINB
//INPUT PINS digital 2-7 PIND
#define PIND_MASK B11111100
//INPUT PINS digitat 8-12 PINB
@@
-9,33
+11,37
@@
//INPUT PINS analog 0-4 PINC
#define PINC_MASK B00011111
//INPUT PINS analog 0-4 PINC
#define PINC_MASK B00011111
-#define INPUT_SIG_PORTD B11111111
-#define INPUT_SIG_PORTC B11111111
-#define INPUT_SIG_PORTB B11111111
+#define INPUT_SIG_PORTD B11000000
+#define INPUT_SIG_PORTB B00011111
+#define INPUT_SIG_PORTC B00010000
+
+#define OUTPUT_SIG_PORTB ( PINB_MASK & ~INPUT_SIG_PORTB )
+// B00011111 & ! B00011111 = 0
+#define OUTPUT_SIG_PORTC ( PINC_MASK & ~INPUT_SIG_PORTC )
+// B00011111 & ! B00010000 = B00001111
+#define OUTPUT_SIG_PORTD ( PIND_MASK & ~INPUT_SIG_PORTD )
+// B11111100 & ! B11000000 = 00111100
union union16 {
byte uint8[2];
uint16_t uint16;
};
union union16 {
byte uint8[2];
uint16_t uint16;
};
+uint8_t zahlen[] = {115,110,46,78,51,83,82,68,99,105,41,73,35,67,50,36,113,108,44,76,49,81,114,100,98,101,37,69,34,66,102,109,111,116,52,84,47,79,57,89,106,97,33,65,42,74,38,45,112,104,40,72,48,80,0,0,103,107,43,75,39,71,70,77} ;
+
union union32 {
byte uint8[4];
uint16_t uint16[2];
uint32_t uint32;
};
union union32 {
byte uint8[4];
uint16_t uint16[2];
uint32_t uint32;
};
-
-//********************************************************************//
-
typedef unsigned char byte;
typedef unsigned char byte;
-//********************************************************************//
-
void start_timer()
{
// timer 1: 2 ms
TCCR1A = 0; // prescaler 1:8, WGM = 4 (CTC)
void start_timer()
{
// timer 1: 2 ms
TCCR1A = 0; // prescaler 1:8, WGM = 4 (CTC)
- TCCR1B = 1<<WGM12 | 1<<CS11; //
- OCR1A = 159; // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
+ TCCR1B = 1<<WGM12 | 1<<CS10 | 1<<CS11; //
+ OCR1A = 65000; // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
// OCR1A = 207; // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
TCNT1 = 0; // reseting timer
TIMSK1 = 1<<OCIE1A; // enable Interrupt
// OCR1A = 207; // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
TCNT1 = 0; // reseting timer
TIMSK1 = 1<<OCIE1A; // enable Interrupt
@@
-48,45
+54,69
@@
void stop_timer() // stop the timer
TIMSK1 = 0; // disable timer interrupt
}
TIMSK1 = 0; // disable timer interrupt
}
-static void PCint(uint8_t port) {
- union32 data;
- data.uint32=0;
- data.uint8[0]=PIND;
- data.uint8[1]=PINC;
- data.uint8[2]=PINB;
- data.uint8[0]|= !PIND_MASK;
- data.uint8[1]|= !PINC_MASK;
- data.uint8[2]|= !PINB_MASK;
- data.uint8[3]=0xff;
- //PINS with signal:
- //1
- //3
- //9
- //14
- //15
- //21
- //22
- //23
-
- for(int i=0;i<32; i++)
- {
- if (! (data.uint32 & 1 ))
- Serial.println(i);
- data.uint32>>=1;
- }
- //Serial.print(data.uint8[1]);
+ISR(TIMER1_COMPA_vect)
+{
+ stop_timer();
+ PCICR|= B111;
+}
+
+static void send_dart(byte input,byte output)
+{
+ byte value=0;
+ while(input>>=1)
+ value++;
+ value<<=3;
+ while(output>>=1)
+ value++;
+
+ uint8_t zahl = zahlen[value];
+ uint8_t multi = zahl >> 5;
+ uint8_t base = zahl & B11111;
+ Serial.print(0+multi);
+ Serial.print("\t");
+ Serial.println(0+base);
+}
+
+static void send_btn(byte btn)
+{
+ uint8_t value=0;
+ while(btn>>=1)
+ value++;
+ Serial.print("btn\t");
+ Serial.println(0+value);
+
+}
+
+static void PCint() {
+ byte PINB_COPY = PINB;
+ byte PINC_COPY = PINC;
+ byte PIND_COPY = PIND;
+ byte output = ( OUTPUT_SIG_PORTC & ~ PINC_COPY ) | (( OUTPUT_SIG_PORTD & ~ PIND_COPY ) <<2 ); // no output on B
+ byte input = ( INPUT_SIG_PORTB & ~ PINB_COPY ) | ( ( INPUT_SIG_PORTC & ~ PINC_COPY ) <<1 ) |( INPUT_SIG_PORTD & ~ PIND_COPY );
+ byte btn = ( PLAYER_SIG_PORTC & ~ PINC_COPY );
+
+ if ( input && output)
+ send_dart(input,output);
+ else if (btn)
+ send_btn(btn);
+ else
+ return;
+
+ //Timeout verhindert zu schnelle Wiederholungen
+ PCICR&= ~ B111; // Disable Interrupt
+ start_timer();
}
SIGNAL(PCINT0_vect) {
}
SIGNAL(PCINT0_vect) {
- PCint(0);
+ PCint();
}
SIGNAL(PCINT1_vect) {
}
SIGNAL(PCINT1_vect) {
- PCint(1);
+ PCint();
}
SIGNAL(PCINT2_vect) {
}
SIGNAL(PCINT2_vect) {
- PCint(2);
+ PCint();
}
void setup()
{
}
void setup()
{
@@
-102,23
+132,13
@@
void setup()
DDRC=0;
PORTC=0;
Serial.begin(57600);
DDRC=0;
PORTC=0;
Serial.begin(57600);
- //Serial.println("starting timer");
PCMSK0=PINB_MASK & INPUT_SIG_PORTB;
PCMSK0=PINB_MASK & INPUT_SIG_PORTB;
- PCMSK1=PINC_MASK & INPUT_SIG_PORTC;
+ PCMSK1=(PINC_MASK & INPUT_SIG_PORTC) | PLAYER_SIG_PORTC;
PCMSK2=PIND_MASK & INPUT_SIG_PORTD;
PCICR|= B111;
PCMSK2=PIND_MASK & INPUT_SIG_PORTD;
PCICR|= B111;
-
-// start_timer();
}
}
-//INPUT PINS digital 2-7 PIND
-//INPUT PINS digitat 8-12 PINB
-//INPUT PINS analog 0-4 PINC
void loop()
{
void loop()
{
-// Serial.Serial.println("foo");
-// return;
-
-
}
}