本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<AT89X51.h>
#define uint unsigned int
#define uchar unsigned char
uchar code LED[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF},
LEDC[4]={0x70,0xB0,0xD0,0xE0},
shuangshu[14]={0x10,0x20,0x01,0x02,0x04,0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x04,0x02};
uchar xuehao=27,dangqian=0,moshi=0,shuju[4]={10,2,7,10},bushu=1,zhongduan=0,yimiao=0;
void huanchong(void)
{
shuju[1]=xuehao/10;
shuju[2]=xuehao%10;
}
void xianshi(void)
{
P0=0xFF;
P2=LEDC[dangqian];
P0=LED[shuju[dangqian]];
if(dangqian==3)
dangqian=0;
else
dangqian++;
}
uchar jian(void)
{
static uchar jianzhi=0,jiancha=0;
uchar i,k;
P3=0xFF;
k=(~P3)&0x3C;
switch (jiancha)
{
case 0:
if(k)
{
jiancha=1;
}
return(0);
case 1:
if(k)
{
for(i=0;i<=4;i++)
{
if(k<(1<<(i+2))) //不用==用<起到多按键仍成立
{
jianzhi=i; //因判断用小于号故当前按键为i-1
break;
}
}
jiancha=2;
}
else
jiancha=0;
return(0);
case 2:
if(!k)
{
jiancha=0;
return(jianzhi);
}
return(0);
default:
break;
}
}
void donghua1(void)
{
switch(bushu)
{
case 1:
P0=0xFF;
P2=LEDC[dangqian];
P0=~0x08;
break;
case 2:
case 3:
case 4:
dangqian++;
P2=LEDC[dangqian];
break;
case 5:
P0=~0x04;
break;
case 6:
P0=~0x40;
break;
case 7:
case 8:
case 9:
dangqian--;
P2=LEDC[dangqian];
break;
case 10:
P0=~0x20;
break;
case 11:
P0=~0x01;
break;
case 12:
case 13:
case 14:
dangqian++;
P2=LEDC[dangqian];
dangqian=0;
break;
default:break;
}
if(bushu==14)
bushu=1;
else
bushu++;
}
void donghua2(void)
{
switch(bushu)
{
case 1:
case 2:
case 3:
case 4:
P0=0xFF;
P2=LEDC[dangqian];
P0=~shuangshu[bushu-1];
break;
case 5:
P2=LEDC[dangqian++];
P0=~shuangshu[bushu-1];
break;
case 6:
case 7:
P0=0xFF;
P2=LEDC[dangqian];
P0=~shuangshu[bushu-1];
break;
case 8:
P0=0xFF;
P2=LEDC[dangqian++];
P0=~shuangshu[bushu-1];
break;
case 9:
case 10:
P0=0xFF;
P2=LEDC[dangqian];
P0=~shuangshu[bushu-1];
break;
case 11:
P0=0xFF;
P2=LEDC[dangqian++];
P0=~shuangshu[bushu-1];
break;
case 12:
case 13:
P0=0xFF;
P2=LEDC[dangqian];
P0=~shuangshu[bushu-1];
break;
case 14:
P0=0xFF;
P2=LEDC[dangqian];
P0=~shuangshu[bushu-1];
dangqian=0;
break;
default:break;
}
if(bushu==14)
bushu=1;
else
bushu++;
}
void main(void)
{
uchar k=0;
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(zhongduan)
{
zhongduan=0;
huanchong();
if(k=jian())
{
switch(k)
{
case 1:
dangqian=0;
bushu=1;
yimiao=0;
if(moshi==2)
moshi=0;
else
moshi++;
P0=0xFF;
break;
case 2:
dangqian=0;
bushu=1;
yimiao=0;
if(moshi==0)
moshi=2;
else
moshi--;
P0=0xFF;
break;
case 3:
if(moshi==0)
{
if(xuehao==42)
xuehao=1;
else
xuehao++;
}
break;
case 4:
if(moshi==0)
{
if(xuehao==1)
xuehao=42;
else
xuehao--;
}
break;
default:break;
}
}
else
{
switch(moshi)
{
case 0:
xianshi();
break;
case 1:
if(yimiao++>200)
{
yimiao=0;
donghua1();
}
break;
case 2:
if(yimiao++>200)
{
yimiao=0;
donghua2();
}
break;
default :break;
}
}
}
}
}
void abb(void) interrupt 1
{
zhongduan=1;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
}
按键P32P33P34P35 数码管 p0
位选P24P25P26P27 |