X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=dart%2Fdart.pde;h=2e5223e9402929ddbfcfc2429a33d29d57d8867c;hb=45434651a9ef34b3f776b55be0a9ef7635a9703b;hp=4c05548c056b8d3480438f10dde2e68cf9ed5298;hpb=6d40a3e8ce0cc74c068f4442a22c2dce5e30b2a1;p=svn42.git diff --git a/dart/dart.pde b/dart/dart.pde index 4c05548..2e5223e 100644 --- a/dart/dart.pde +++ b/dart/dart.pde @@ -12,6 +12,13 @@ #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; @@ -23,19 +30,14 @@ union union32 { uint32_t uint32; }; - -//********************************************************************// - typedef unsigned char byte; -//********************************************************************// -/* void start_timer() { // timer 1: 2 ms TCCR1A = 0; // prescaler 1:8, WGM = 4 (CTC) - TCCR1B = 1< 0.08ms @ 16 MHz -> 1*alpha + TCCR1B = 1< 0.08ms @ 16 MHz -> 1*alpha // OCR1A = 207; // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha TCNT1 = 0; // reseting timer TIMSK1 = 1<>=1; - } - //Serial.print(data.uint8[1]); + +ISR(TIMER1_COMPA_vect) +{ + stop_timer(); + PCICR|= B111; +} + + +byte last_input=0; +byte last_output=0; +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 ); + + if (!input) + return; + if (!output) + return; + //if (last_input==input && last_output==output) + //return; + last_input=input; + last_output=output; +// Serial.print(output,HEX); +// Serial.print('\t'); +// Serial.print(input,HEX); +// Serial.print('\t'); + + byte value=0; + while(input>>=1) + value++; + value<<=3; + while(output>>=1) + value++; + Serial.println(value,HEX); + PCICR&= ~ B111; // Disable Interrupt + start_timer(); } SIGNAL(PCINT0_vect) { - PCint(0); + PCint(); } SIGNAL(PCINT1_vect) { - PCint(1); + PCint(); } SIGNAL(PCINT2_vect) { - PCint(2); + PCint(); } void setup() { @@ -109,7 +120,6 @@ void setup() PCMSK1=PINC_MASK & INPUT_SIG_PORTC; PCMSK2=PIND_MASK & INPUT_SIG_PORTD; PCICR|= B111; - // start_timer(); } @@ -121,6 +131,4 @@ void loop() { // Serial.Serial.println("foo"); // return; - - }