|
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit EW_LED2=P2^3;
sbit EW_LED1=P2^2;
sbit SN_LED2=P2^1;
sbit SN_LED1=P2^0;
sbit SN_Yellow=P1^6;
sbit SN_Red=P1^7;
sbit EW_Yellow=P1^2;
sbit EW_Red=P1^3;
bit Flag_SN_Yellow;
bit Flag_EW_Yellow;
char Time_EW;
char Time_SN;
uchar EW=10,SN=10,EWL=3,SNL=3;
uchar EW1=10,SN1=10,EWL1=3,SNL1=3;
uchar code table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code s[9]={0x28,0x48,0x18,0x48,0x82,0x84,0x81,0x84,0x88};
void delay_ms(unsigned int x)
{
unsigned int i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void Display(void)
{
char h,l;
h=Time_EW/10;
l=Time_EW%10;
P0=table[l];
EW_LED2=1;
delay_ms(1);
EW_LED2=0;
P0=table[h];
EW_LED1=1;
delay_ms(1);
EW_LED1=0;
h=Time_SN/10;
l=Time_SN%10;
P0=table[l];
SN_LED2=1;
delay_ms(1);
SN_LED2=0;
P0=table[h];
SN_LED1=1;
delay_ms(1);
SN_LED1=0;
}
void timer0(void)interrupt 1 using 1
{
static uchar count;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==10)
{
if(Flag_SN_Yellow==1)
{SN_Yellow=~SN_Yellow;}
if(Flag_EW_Yellow==1)
{EW_Yellow=~EW_Yellow;}
}
if(count==20)
{
Time_EW--;
Time_SN--;
if(Flag_SN_Yellow==1)
{SN_Yellow=~SN_Yellow;}
if(Flag_EW_Yellow==1)
{EW_Yellow=~EW_Yellow;}
count=0;
}
}
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
Time_EW=3;
Time_SN=3;
while(Time_SN>=0||Time_EW>=0)
{
Flag_EW_Yellow=0;
P1=s[8];
Display();
}
while(1)
{
Time_EW=EW;
Time_SN=SN;
while(Time_SN>=4)
{
Flag_EW_Yellow=0;
P1=s[0];
Display();
}
P1=0x00;
while(Time_SN>=0)
{
Flag_SN_Yellow=1;
EW_Red=1;
Display();
}
EW=EW1;
SN=SN1;
EWL=EWL1;
SNL=SNL1;
Time_EW=SN;
Time_SN=EW;
while(Time_EW>=4)
{
Flag_SN_Yellow=0;
P1=s[4];
Display();
}
P1=0x00;
while(Time_EW>=0)
{
Flag_EW_Yellow=1;
SN_Red=1;
Display();
}
EW=EW1;
SN=SN1;
EWL=EWL1;
SNL=SNL1;
}
}
|
-
1.png
(83.15 KB, 下载次数: 91)
|