#include #define f_cpu 8000000ul #include #define key_prt portc #define key_ddr ddrc #define key_pin pinc unsigned char keypad[4][4] = {{'0','1','2','3'}, {'4','5','6','7'}, {'8','9','a','b'}, {'c','d','e','f'}}; int main () { unsigned char colloc, rowloc; ddrd = 0xff; while(1) { while(1) { key_ddr = 0xf0; key_prt = 0xff; do { key_prt &= 0x0f; asm("nop"); colloc = (key_pin & 0x0f); }while(colloc != 0x0f); do { do { _delay_ms(20); colloc = (key_pin & 0x0f); }while(colloc == 0x0f); _delay_ms (20); colloc = (key_pin & 0x0f); }while(colloc == 0x0f); key_prt = 0xef; asm("nop"); colloc = (key_pin & 0x0f); if(colloc != 0x0f) { rowloc = 0; break; } key_prt = 0xdf; asm("nop"); colloc = (key_pin & 0x0f); if(colloc != 0x0f) { rowloc = 1; break; } key_prt = 0xbf; asm("nop"); colloc = (key_pin & 0x0f); if(colloc != 0x0f) { rowloc = 2; break; } key_prt = 0x7f; asm("nop"); colloc = (key_pin & 0x0f); if(colloc != 0x0f) { rowloc = 3; break; } } if(colloc == 0x0e) portd = keypad[rowloc][0]; else if(colloc == 0x0d) portd = keypad[rowloc][1]; else if(colloc == 0x0b) portd = keypad[rowloc][2]; else portd = keypad[rowloc][3]; } return 0; }