/*MCU:AT89S52*/
#include
#include
#define uchar unsigned char
int key;
int del;
void Key_Scan(void);
/************主程序*************/
void main(void)
{
void Key_Scan(void);
void delay(int);
while(1)
{
Key_Scan();
delay(2000);
}
}
/********矩键查寻键值4*4程序******/
void Key_Scan(void)
{
uchar readkey;
uchar x_temp,y_temp;
P1=0x0f;
x_temp=P1&0x0f;
if(x_temp==0x0f) goto keyout;
P1=0xf0;
y_temp=P1&0xf0;
readkey=x_temp|y_temp;
readkey=~readkey;
switch(readkey)
{
case 0x11:key=0;P2=key; break;
case 0x21:key=1;P2=key; break;
case 0x41:key=2;P2=key; break;
case 0x81:key=3;P2=key; break;
case 0x12:key=4;P2=key; break;
case 0x22:key=5;P2=key; break;
case 0x42:key=6;P2=key; break;
case 0x82:key=7;P2=key; break;
case 0x14:key=8;P2=key; break;
case 0x24:key=9;P2=key; break;
case 0x44:key=10;P2=key;break;
case 0x84:key=11;P2=key;break;
case 0x18:key=12;P2=key;break;
case 0x28:key=13;P2=key;break;
case 0x48:key=14;P2=key;break;
case 0x88:key=15;P2=key;break;
default: key=16;P2=key;break;
}
keyout:_nop_();
}
/************延时程序*************/
void delay(del)
{
for(del;del>0;del--);
}
为了方便大家更好的学习,您还可以关注畅学电子和EDA的公众号,每天推送相关知识,希望能对你的学习有所帮助!