#ifndef __KEY_C #define __KEY_C #include "key.h" unsigned char testkey( void ) { unsigned int val; // unsigned char lval; ADMUX = KEYADCCHANNEL; //channel 0 PORTA0 ADCSRA = 199;//adps0,1,2 = 1 = prescaler = 128 //with 14,7456Mhz we have 115,24Khz //normal single shoot,ADEN,ADSC ON while( ! ( ADCSRA & 16 ) ){;} // lval = ADCL; // val = ADCH; // val = val << 8; // val = val & 0xff00; // val = val | lval; val = ADCW; if( val < 950 ){ if( val > 850 ){ return( KEY_7 ); } if( val > 750 ){ return( KEY_6 ); } if( val > 650 ){ return( KEY_5 ); } if( val > 500 ){ return( KEY_4 ); } if( val > 350 ){ return( KEY_3 ); } if( val > 150 ){ return( KEY_2 ); } if( val > 50 ){ return( KEY_1 ); } return( KEY_0 ); } return(NOKEY); } /* reads keyinput. if a key is pressed, tests ist for three times, with a difference of 10 ms between every test. If same key pressed after this tests, function waits till key is released, then it returns the key. Otherwise 0 is returned. */ unsigned char readkey( void ) { unsigned char val; val = testkey(); if( val == NOKEY ){ return( NOKEY ); } Delay1ms(10); if( (testkey()) != val ){ return( NOKEY ); } Delay1ms(10); if( (testkey()) != val ){ return( NOKEY ); } while(testkey() == val){;} return(val); } #endif