//Drehgeber ///////////////////////////////////////////////////////////////////////////////////////////////////////// #define XTAL 8e6 // 8MHz #include #include // this is needed for int8_t, etc. // target: ATmega328 //------------------------------------------------------------------------ #define PHASE_A (PIND & 1<<2) // PORTB pin 1 MODIFY TO SUIT YOUR NEEDS #define PHASE_B (PIND & 1<<3) // PORTB pin 3 MODIFY TO SUIT YOUR NEEDS //#define LEDS_DDR DDRC //#define LEDS PORTC // LEDs against VCC volatile int8_t enc_delta; // -128 ... 127 static int8_t last; void encode_init( void ) { int8_t new; new = 0; if( PHASE_A ) new = 3; if( PHASE_B ) new ^= 1; // convert gray to binary last = new; // power on state enc_delta = 0; DDRD.3=1; PORTD.3=1; DDRD.2=1; PORTD.2=1; // ********************************************************************* // Timer/Counter 0 initialization BY THE WIZARD // Clock source: System Clock // Clock value: 250.000 kHz // Mode: CTC top=OCR0A // OC0A output: Disconnected // OC0B output: Disconnected // Timer Period: 1 ms @ 8MHz? TCCR0A=(0<> 1; } /////////////////////////////////////////////////