#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit P32=P3^2;
sbit P33=P3^3;
sbit duan=P2^6;
sbit wei=P2^7;
bit flag1,flag;
uchar code duan1[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code wei1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char temp[6];
void init()//初始化函数
{
TMOD=0x01; //用定时器0方式1
EA=1; //打开中断
ET0=1; //打开定时器0中断
TR0=1;
}
void display()
{
static unsigned char i;
duan=1;
P0=0;
duan=0;
wei=1;
P0=wei1[i]; //北十位
wei=0;
duan=1;
P0=temp[i]; //北个位
duan=0;
i++;
if(i==6)
i=0;
}
void main()
{
char shu1,shu2;
unsigned char flag3,flag4;
shu1=30;
shu2=35;
init();
if(shu1>10)
temp[0]=duan1[shu1/10];
else
temp[0]=0;
temp[1]=duan1[shu1%10];
if(shu2>10)
temp[2]=duan1[shu2/10];
else
temp[2]=0;
temp[3]=duan1[shu2%10];
while(1)
{
if(flag)
{
flag=0;
shu1--;
shu2--;
if(shu1<0)
flag3++;
if(flag3==1)
shu1=5;
shu1--;
if(shu1>10)
temp[0]=duan1[shu1/10];
else
temp[0]=0;
temp[1]=duan1[shu1%10];
if(shu2>10)
temp[2]=duan1[shu2/10];
else
temp[2]=0;
temp[3]=duan1[shu2%10];
if(flag3==2)
if(shu1>10)
temp[0]=duan1[shu1/10];
else
temp[0]=0;
temp[1]=duan1[shu1%10];
if(shu2>10)
temp[2]=duan1[shu2/10];
else
temp[2]=0;
temp[3]=duan1[shu2%10]; shu1=35;
if(flag3==3)
shu1=30;
shu1--;
if(shu1>=10)
temp[0]=duan1[shu1/10];
else
temp[0]=0;
temp[1]=duan1[shu1%10];
if(shu2==0)
flag4++;
if(flag4==1)
shu2=30;
if(flag4==2)
shu2=5;
if(flag4==3)
{
shu2=35;
flag4=0;
}
if(shu2>=10)
temp[2]=duan1[shu2/10];
else
temp[2]=0;
temp[3]=duan1[shu2%10];
}
}
}
void timer() interrupt 1 using 1
{
static unsigned int shu;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
shu++;
if(shu==100)
{
flag=1;
shu=0;
}
display();
} |