2 #include <avr/interrupt.h>
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
12 #define INPUT_SIG_PORTD B11000000
13 #define INPUT_SIG_PORTB B00011111
14 #define INPUT_SIG_PORTC B00010000
16 #define OUTPUT_SIG_PORTB ( PINB_MASK & ~INPUT_SIG_PORTB )
17 // B00011111 & ! B00011111 = 0
18 #define OUTPUT_SIG_PORTC ( PINC_MASK & ~INPUT_SIG_PORTC )
19 // B00011111 & ! B00010000 = B00001111
20 #define OUTPUT_SIG_PORTD ( PIND_MASK & ~INPUT_SIG_PORTD )
21 // B11111100 & ! B11000000 = 00111100
34 //********************************************************************//
36 typedef unsigned char byte;
38 //********************************************************************//
43 TCCR1A = 0; // prescaler 1:8, WGM = 4 (CTC)
44 TCCR1B = 1<<WGM12 | 1<<CS11; //
45 OCR1A = 159; // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
46 // OCR1A = 207; // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
47 TCNT1 = 0; // reseting timer
48 TIMSK1 = 1<<OCIE1A; // enable Interrupt
51 void stop_timer() // stop the timer
54 TCCR1B = 0; // no clock source
55 TIMSK1 = 0; // disable timer interrupt
60 static void PCint(uint8_t port) {
61 byte input = ( INPUT_SIG_PORTB & ~ PINB ) | ( ( INPUT_SIG_PORTC & ~ PINC ) <<1 ) |( INPUT_SIG_PORTD & ~ PIND );
62 byte output = ( OUTPUT_SIG_PORTC & ~ PINC ) | (( OUTPUT_SIG_PORTD & ~ PIND ) <<2 ); // no output on B
66 if (last_input==input && last_output==output)
70 Serial.print(output,HEX);
72 Serial.println(input,HEX);
89 // pinMode(RF433_PIN, INPUT); // set pin to input
90 // digitalWrite(RF433_PIN, LOW); // turn of pullup resistors
101 //Serial.println("starting timer");
102 PCMSK0=PINB_MASK & INPUT_SIG_PORTB;
103 PCMSK1=PINC_MASK & INPUT_SIG_PORTC;
104 PCMSK2=PIND_MASK & INPUT_SIG_PORTD;
111 //INPUT PINS digital 2-7 PIND
112 //INPUT PINS digitat 8-12 PINB
113 //INPUT PINS analog 0-4 PINC
116 // Serial.Serial.println("foo");