|
#include "keyboard.h"
//extern unsigned char flag_eprom;
void keyboard_init(void)
{
DDRA=0xf0; //PA.0-PA.3为输入,PD.4-PD.7为输出
PORTA=0xf0; //PA.4-PA.7输出高电平
}
/*按键扫描函数*/
unsigned char read_keyboard(void)
{
unsigned char key_value=0;
unsigned char key_row=0x01;//用于行扫描
unsigned char key_col=0x10;//用于列扫描
unsigned char i,j=0;
for(i=1;i<=4;i++)
{
PORTA=0xf0;
PORTA=~key_col;
key_col<<=1;
if((PINA&0x0f)<0x0f)
{
delay_ms(10);
if((PINA&0x0f)<0x0f)
{
for(j=0;j<4;j++)
{
if((PINA&key_row)==0)
{
key_value=(i+j*4);
while((PINA&0x0f)<0x0f);
switch(key_value)
{
case 1: return 4; break;
case 2: return 1; break;
case 3: return 2; break;
case 4: return 3; break;
case 5: return 5; break;
case 6: return 6; break;
case 7: return 7; break;
case 8: return 8; break;
case 9: return 12;break;
case 10:return 9; break;
case 11:return 10;break;
case 12:return 11;break;
case 13:return 13;break;
case 14:return 14;break;
case 15:return 15;break;
case 16:return 16;break;
default:return 0; break;
}
}
key_row<<=1;
}
}
}
}
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|