#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0xff,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar Pre_KeyNo=16,KeyNo=16;
uchar q,t,f,j,l;
void DelayMS(uint x)
{
uchar i;
while(x--) for(i=0;i<120;i++);
}
void Keys_Scan()
{
uchar a;
P1=0x07;
DelayMS(1);
a=P1^0x07;
switch(a)
{
case 1:KeyNo=0;break;
case 2:KeyNo=1;break;
case 4:KeyNo=2;break;
}
P1=0x38;
DelayMS(1);
a=P1>>3^0x07;
switch(a)
{
case 1:KeyNo+=0;break;
case 2:KeyNo+=3;break;
case 4:KeyNo+=6;break;
}
}
void main()
{
P0=0xff;P1=0x38;
while(1)
{
if( P1!=0x38)
{
l=0; DelayMS(1);
l++; DelayMS(1000);
}
P1=0x38;
if(l=1) Keys_Scan();
{
P2=0x01;q=KeyNo;
P0=~DSY_CODE[q];
Pre_KeyNo=KeyNo;
DelayMS(100);
}
if(l=2) Keys_Scan();
{
P2=0x02; t=KeyNo;
P0=~DSY_CODE[t];
Pre_KeyNo=KeyNo;
DelayMS(100);
}
if(l=3) Keys_Scan();
{
P2=0x04; f=KeyNo;
P0=~DSY_CODE[f];
Pre_KeyNo=KeyNo;
DelayMS(100);
}
if(l=4) Keys_Scan();
{
P2=0x08; j=KeyNo;
P0=~DSY_CODE[j];
Pre_KeyNo=KeyNo;
DelayMS(100);
}
}
}
|