#include<reg52.h>
#define dataport P0
#define uchar unsigned char
#define uint unsigned int
uchar code duanma[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar tempdata[8];
sbit key1=P3^3;
sbit key2=P3^4;
sbit latch1=P2^2;
sbit latch2=P2^3;
void delayus2x(uchar t);
void delayms(uchar t);
void display(uchar firstbit,uchar num);
void main(void)
{
uchar num=0;
key1=1;
key2=1;
while(1)
{
if(!key1)
{
delayms(10);
if(!key1)
{
while(!key1);
{
if(num<9)
num++;
}
}
}
if(!key2)
{
delayms(10);
if(!key2)
{
while(!key2);
{
if(num>0)
num--;
}
}
}
tempdata[0]=duanma[num%10];
display(0,1);
}
}
void delayus2x(uchar t)
{
while(--t);
}
void delayms(uchar t)
{
while(t--)
{
delayus2x(245);
delayus2x(245);
}
}
void display(uchar firstbit,uchar num)
{
uchar i;
for(i=0;i<num;i++)
{
dataport=0;
latch1=1;
latch1=0;
dataport=weima[firstbit+i];
latch2=1;
latch2=0;
dataport=tempdata[i];
latch1=1;
latch1=0;
delayms(2);
}
}
|