|
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^7;
sbit dula=P2^6;
uchar temp,num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
void delay(uchar z);
uchar keyscan();
void display(uchar aa);
void main()
{
num=17;
dula=1;
P0=0;
dula=0;
wela=1;
P0=0xc0;
wela=0;
while(1)
{
display(keyscan());
}
}
void display(uchar aa)
{
dula=1;
P0=table[aa-1];
dula=0;
}
uchar keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp!=0xf0);
{
temp=P3;
temp=temp&0xf0;
}
}
}
return num;
}
void delay(uchar z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
代碼是先寫,后照范例改
|
-
1.PNG
(135.24 KB, 下載次數(shù): 142)
下載附件
2022-1-2 10:22 上傳
-
2.PNG
(34.44 KB, 下載次數(shù): 139)
下載附件
2022-1-2 10:22 上傳
-
-
范例.zip
2022-1-2 10:38 上傳
點擊文件名下載附件
599 Bytes, 下載次數(shù): 2
|