本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0,0xf9,0xa4,0xb0,0x99,0x92};
unsigned char code wei[]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80};
unsigned char temp[8]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF};
sbit P20=P2^0;
sbit P21=P2^1;
sbit P35=P3^5;
void display(int a,int b)
{
int i;
P1=0xff;
P20=1;
P20=0;
P1=wei[i+a];
P21=1;
P21=0;
P1=temp[i];
P20=1;
P20=0;
i++;
if(i==b)
i=0;
}
void init()
{
TMOD=0x01;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
EA=1;
ET0=1;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar key_1()
{
uchar key_l,key_h,key;
P3=0xf0;
key_l=P3;
key_l=key_l&0xf0;
if(key_l!=0xf0)
{
delay(10);
if(key_l!=0xf0)
{
key_l=P3&0xf0;
key_l=key_l|0x0f;
P3=key_l;
key_h=P3;
key_h=key_h&0x0f;
key_l=key_l&0xf0;
key=key_l+key_h;
while(P3&0x0f!=0x0f);
delay(5);
return key;
}
return 0xff;
}
}
uchar keyscan()
{
switch(key_1())
{
case 0x7e:return 0;break;//0 按下相应的键显示相对应的码值
case 0x7d:return 1;break;//1
case 0x7b:return 2;break;//2
case 0x77:return 3;break;//3
case 0xbe:return 4;break;//4
case 0xbd:return 5;break;//5
case 0xbb:return 6;break;//6
case 0xb7:return 7;break;//7
case 0xde:return 8;break;//8
case 0xdd:return 9;break;//9
case 0xdb:return 10;break;//a
case 0xd7:return 11;break;//b
case 0xed:return 13;break;//d
case 0xee:return 12;break;//c
case 0xeb:return 14;break;//e
case 0xe7:return 15;break;//f
default:return 0xff;break;
}
}
void main()
{
uchar num,i,j;
init();
P35=0;
while(1)
{ num=keyscan();
if(num!=0xff)
{
if(i<8)
{
temp[i]=duan[num];
}
i++;
if(i==9)//多出一个按键输入为了清屏 原本应该为8
{
i=0;
// for(j=0;j<8;j++)//清屏
// temp[j]=0XFF;
}
}
}
}
void time0()interrupt 1
{
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
display(0,8);
} |