4X4鍵盤測試程序
/***********************Copyright(c)**************************
**------------------------------------------------------------
**Created by: 康利平
**Descriptions: The original version
**Descriptions: 鍵盤測試程序1
**------------------------------------------------------------*/
#include
#define uchar unsigned char
#define uint unsigned int
sbit P3_4=P3^4;
sbit P3_5=P3^5;
sbit P3_6=P3^6;
sbit P3_7=P3^7;
sbit P1_0=P1^0;
sbit P1_2=P1^2;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
uchar code tablebit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar table1[]={0,16,16,16,16,16,16,16};
uchar temp,key,count1;
uchar keycount;
void delay(uint t)
{
uchar kk,nn;
for(kk=0;kk<200;kk++)
for(nn=0;nn
void change(uchar *p,uchar count)
{
while(count>0)
{
*(p+count)=*(p+count-1);
count--;
}
}
void keyscan()
{
P3=0xff;
P3_4=0;
temp=P3;
temp=P3&0x0f;
if(temp!=0x0f)
{
delay(50);
temp=P3;
temp=temp&0x0f;
if(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
switch(temp)
{
case 0x0e:key=0;break;
case 0x0d:key=4;break;
case 0x0b:key=8;break;
case 0x07:key=12;break;
}
if((key>=0)&&(key<16))
{
keycount++;
if(keycount<8)
{
change(table1,keycount);
table1[0]=key;
}
}
else {keycount=8;}
temp=P3;P1_2=~P1_2;
temp=temp&0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
}
}
}
P3=0xff;
P3_5=0;
temp=P3;
temp=P3&0x0f;
if(temp!=0x0f)
{
delay(50);
temp=P3;
temp=temp&0x0f;
if(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
switch(temp)
{
case 0x0e:key=1;break;
case 0x0d:key=5;break;
case 0x0b:key=9;break;
case 0x07:key=13;break;
}
if((key>=0)&&(key<16))
{
keycount++;
if(keycount<8)
{
change(table1,keycount);
table1[0]=key;
}
}
else {keycount=8;}
temp=P3;P1_2=~P1_2;
temp=temp&0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
}
}
}
P3=0xff;
P3_6=0;
temp=P3;
temp=P3&0x0f;
if(temp!=0x0f)
{
delay(50);
temp=P3;
temp=temp&0x0f;
if(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
switch(temp)
{
case 0x0e:key=2;break;
case 0x0d:key=6;break;
case 0x0b:key=10;break;
case 0x07:key=14;break;
}
if((key>=0)&&(key<16))
{
keycount++;
if(keycount<8)
{
change(table1,keycount);
table1[0]=key;
}
}
else {keycount=8;}
temp=P3;P1_2=~P1_2;
temp=temp&0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
}
}
}
P3=0xff;
P3_7=0;
temp=P3;
temp=P3&0x0f;
if(temp!=0x0f)
{
delay(50);
temp=P3;
temp=temp&0x0f;
if(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
switch(temp)
{
case 0x0e:key=3;break;
case 0x0d:key=7;break;
case 0x0b:key=11;break;
case 0x07:key=15;break;
}
if((key>=0)&&(key<16))
{
keycount++;
if(keycount<8)
{
change(table1,keycount);
table1[0]=key;
}
}
else {keycount=8;}
temp=P3;
P1_2=~P1_2;
temp=temp&0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp&0x0f;
}
}
}
}
void main()
{
TMOD=0x01;
TH0=(65536-6000)/256;
TL0=(65536-6000)%256;
ET0=1;
TR0=1;
EA=1;
while(1)
{
keyscan();
}
}
void time0() interrupt 1
{
TH0=(65536-6000)/256;
TL0=(65536-6000)%256;
P2=tablebit[count1];
P0=table[table1[count1]];
count1++;
if(count1==8)
{count1=0;}
}
評論