|
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit red_a=P1^0;
sbit yellow_a=P1^1;
sbit green_a=P1^2;
sbit red_b=P1^3;
sbit yellow_b=P1^4;
sbit green_b=P1^5;
sbit dxwei1=P1^6;
sbit dxwei2=P1^7;
sbit nbwei1=P2^0;
sbit nbwei2=P2^1;
int aa,bai,shi,ge,bb;
int shi1,ge1,shi2,ge2;
int a;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code table1[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};
void delay(int z);
void init(int a);
void display(int shi1,int shi2,int ge1,int ge2);
void xtimer0();
void init1();
void init2();
void init3();
void init4();
void init5();
//void xint1();
//void xint0();
void led_on();
void led_off();
void delay(int z)
{
int x,y;
for(x=0;x<z;x--)
for(y=0;y<110;y--);
}
void main()
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
EA=1;
ET0=1;
init1();
while(1)
{
init2();
init3();
init4();
init5();
}
}
void init1()
{
int temp;
temp=5;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
red_a=0;
red_b=0;
green_a=1;
green_b=1;
yellow_a=1;
yellow_b=1;
if(aa==20)
{
aa=0;
temp--;
}
shi1=shi2=temp/10;
ge1=ge2=temp%10;
if(temp==0)
{
temp=5;
break;
}
display(ge1,shi1,ge2,shi2);
}
}
void init2()
{
int temp;
temp=26;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
red_a=1;
red_b=0;
green_a=0;
green_b=1;
yellow_a=1;
yellow_b=1;
if(aa==20)
{
aa=0;
temp--;
}
shi1=(temp+5)/10;
ge1=(temp+5)%10;
shi2=temp/10;
ge2=temp%10;
if(temp==0)
{
temp=26;
break;
}
display(ge1,shi1,ge2,shi2);
}
}
void init3()
{
int temp;
temp=6;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
red_a=1;
red_b=0;
green_a=1;
green_b=1;
if(aa==20)
{
aa=0;
temp--;
}
yellow_a=~yellow_a;
shi1=temp/10;
ge1=temp%10;
shi2=shi;
ge2=ge1;
if(temp==0)
{
temp=6;
break;
}
display(ge1,shi1,ge2,shi2);
}
}
/*void init3()
{
int temp;
temp=6;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
red_b=0;
green_a=1;
if(aa==20)
{
aa=0;
temp--;
}
yellow_a=~yellow_a;
shi1=temp/10;
ge1=temp%10;
shi2=shi;
ge2=ge1;
if(temp==0)
{
temp=6;
break;
}
display(ge1,shi1,ge2,shi2);
}
}*/
void init4()
{
int temp;
temp=26;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
red_a=0;
red_b=1;
green_a=1;
green_b=0;
yellow_a=1;
yellow_b=1;
if(aa==20)
{
aa=0;
temp--;
}
shi2=(temp+5)/10;
ge2=(temp+5)%10;
shi1=temp/10;
ge1=temp%10;
if(temp==0)
{
temp=26;
break;
}
display(ge1,shi1,ge2,shi2);
}
}
void init5()
{
int temp;
temp=6;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
red_a=0;
red_b=1;
green_a=1;
green_b=1;
if(aa==20)
{
aa=0;
temp--;
}
yellow_b=~yellow_b;
shi1=temp/10;
ge1=temp%10;
shi2=shi;
ge2=ge1;
if(temp==0)
{
temp=6;
break;
}
display(ge1,shi1,ge2,shi2);
}
}
void display(ge1,shi1,ge2,shi2)
{
dxwei1=0;
dxwei2=1;
nbwei1=1;
nbwei2=1;
P0=table[ge1];
delay(5);
dxwei1=1;
dxwei2=0;
nbwei1=1;
nbwei2=1;
P0=table[shi1];
delay(5);
dxwei1=1;
dxwei2=1;
nbwei1=0;
nbwei2=1;
P0=table[ge2];
delay(5);
dxwei1=1;
dxwei2=1;
nbwei1=1;
nbwei2=0;
P0=table[shi2];
delay(5);
}
/*void xint0() interrupt 0
{
red_a=0;
red_b=0;
green_a=1;
green_b=1;
yellow_a=1;
yellow_b=1
dxwei1=0;
dxwei2=0;
nbwei1=0;
nbwei2=0;
delay(2);
return;
}
void xint1() interrupt 0
{
red_a=1;
red_b=1;
green_a=0;
green_b=0;
yellow_a=1;
yellow_b=1
dxwei1=0;
dxwei2=0;
nbwei1=0;
nbwei2=0;
delay(2);
return;
}*/
void xtimer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
a++;
}
|
评分
-
查看全部评分
|