/************************************************************************/ /* */ /* Key + LED over the same wire (4 times) */ /* */ /* Author: P. Dannegger */ /* CoAuthor: F. Brunner */ /* */ /************************************************************************/ #define F_CPU 1000000L #include #include #include uint8_t key_state; // debounced key state: // bit = 1: key pressed uint8_t key_press; // key press detect void wait7(void) { // short delay to settle ADC MUX _delay_us(0.5); } static uint8_t scan_tast( void ) { uint8_t saveport = PORTB; uint8_t keys=0; PORTB = 0xFF; // weak pull ups on DDRB = 0; ACSR = 1<1: key press detect } static uint8_t get_key_press( uint8_t key_mask ) { // cli(); key_mask &= key_press; // read key(s) key_press ^= key_mask; // clear key(s) // sei(); return key_mask; } int main( void ) { DDRB = 0xFF; PORTB = 0; for(;;){ _delay_ms(10); // debouncing time key_poll(); PORTB ^= get_key_press( 0xFF ); // toggle on key press } }