#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar count;
uint disnum,disnum1;
uchar wei;
sbit wei1=P3^0;
sbit wei2=P3^1;
sbit wei3=P3^2;
sbit wei4=P3^3;
uchar code led[]=
{
0x0a,0x22,0x11,0x11,0x14
};
uchar code tabledu[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
uchar code shiduan[]=
{
5,3,2
};
uchar code shiduan1[]=
{
3,2,5
};
void display(uchar,uchar);
void display1(uchar,uchar);
void delay(uchar);
void main()
{
uint i,j,m;
uchar shi,ge;
uchar shi1,ge1;
disnum=shiduan[0];
disnum1=shiduan1[0];
P1=0x00;
EA=1;
ET1=1;
TMOD=0x10;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
while(1)
{
shi=disnum/10;
shi1=disnum1/10;
ge=disnum%10;
ge1=disnum1%10;
if(count==20)
{
count=0;
disnum1--;
disnum--;
if(disnum==0)
{
i++;
disnum=shiduan[i];
if(i==3)
{
disnum=shiduan[0];
i=0;
}
}
if(disnum1==0)
{
j++;
disnum1=shiduan1[j];
if(j==3)
{
disnum1=shiduan1[0];
j=0;
}
}
}
display(shi,ge);
display1(shi1,ge1);
m=i+j;
P1=led[m];
/* if(i+j==6)
{
i=0;
j=0;
}*/
}
}
void tim1() interrupt 3 using 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++;
}
void display(uchar shi,uchar ge)
{
wei1=0;
shi=disnum/10;
P0=tabledu[shi];
delay(10);
wei1=1;
wei2=0;
ge=disnum%10;
P0=tabledu[ge];
delay(10);
wei2=1;
}
void display1(uchar shi1,uchar ge1)
{
wei3=0;
shi1=disnum1/10;
P2=tabledu[shi1];
delay(10);
wei3=1;
wei4=0;
ge1=disnum1%10;
P2=tabledu[ge1];
delay(10);
wei4=1;
}
void delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=255;b>0;b--);
}
给你贴出来--------- |