编写的是s6,s7,s8,s9的按键可效果却是s6,s10,s14,s18
#include <STC89.H>
#define uchar unsigned char
#define uint unsigned int
sbit de=P2^6;
sbit we=P2^7;
sbit dze=P2^4;
sbit line1= P3^4;
sbit line2= P3^5;
sbit line3= P3^6;
sbit line4= P3^7;
uchar code array[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
uchar code array2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uint g,s,b,gsb,i,x,y,z,temp;
void desplay(gsb);
void keyscan();
void main()
{
z=111;
dze=1;//关闭点阵
temp=0;
while(1)
{
keyscan();
desplay(temp);
}
}
void desplay(gsb)//数码管扫描显示数字
{
b=gsb/100;
s=gsb/10-(b*10);
g=gsb-(s*10)-(b*100);
for(i=0;i<3;i++)
{
de=1;
if(i==0)
{
P0=array[b];
}
if(i==1)
{
P0=array[s];
}
if(i==2)
{
P0=array[g];
}
de=0;
P0=0xff;
we=1;
P0=array2[i];
we=0;
for(x=0;x<1000;x++)
{
}
P0=0xff;
//关闭所有P0口数据,方便下次循环用,否则下次循环de=1时会有干扰,鬼影
}
}
//uint checkkey()//独立键盘
//{
// key=1;
// y=0;
// if(key==0)
// {
// y=1;
// de=1;//按键时关闭数码管显示
// P0=0;
// de=0;
// we=1;
// we=0;
// while(key==0)//松手检测
// {
//
//
// }
// }
// return y;
//}
void keyscan()//矩阵键盘
{
while(1)
{
line1=0;
line2=1;
line3=1;
line4=1;
switch(P3)
{
case 0xee:
temp=100;
break;
case 0xed:
temp=101;
break;
case 0xeb:
temp=102;
break;
case 0xe7:
temp=103;
break;
}
line1=1;
line2=0;
line3=1;
line4=1;
switch(P3)
{
case 0xde:
temp=104;
break;
case 0xdd:
temp=105;
break;
case 0xdb:
temp=106;
break;
case 0xd7:
temp=107;
break;
}
line1=1;
line2=1;
line3=0;
line4=1;
switch(P3)
{
case 0xbe:
temp=108;
break;
case 0xbd:
temp=109;
break;
case 0xbb:
temp=110;
break;
case 0xb7:
temp=111;
break;
}
line1=1;
line2=1;
line3=1;
line4=0;
switch(P3)
{
case 0x7e:
temp=112;
break;
case 0x7d:
temp=113;
break;
case 0x7b:
temp=114;
break;
case 0x77:
temp=115;
break;
}
if(temp!=0)
{
break;
}
}
}
|