#include #include #define xtal 1000000 unsigned char key; int i; char buffer[2]; #asm .equ__lcd_port=0X1B;PORTA #endasm #include #include flash char keytable[16]={0xee,0xed,0xeb,0xe7,0xde,0xdd,0xdb,0xd7,0xbe,0xbd,0xbb,0xb7,0x7e,0x7d,0x7b,0x77}; void main(void) { DDRB=0XFF; PORTB=0XFF; while(1) { int butnum=0; DDRB=0X0F; PORTB=0XF0; delay_us(5); key=PINB; delay_us(10); DDRB=0XF0; PORTB=0X0F; delay_us(5); key=PINB|key; if(key!=0XFF) { for(i=0;i<16;i++) { if(key==keytable[i]) { butnum=i+1; break; } } } if(butnum!=0) { lcd_clear(); lcd_gotoxy(0,0); sprintf(buffer,"%2u",butnum); lcd_puts(buffer); delay_ms(1000); } } }