|
#include <reg52.h>
#define u8 unsigned int
#define u16 unsigned char
#define GPIO_dig P0
#define GPIO_traffic P1
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit RED_1=P1^0;
sbit GREEN_1=P1^1;
sbit RED_2=P1^2;
sbit YELLOW_2=P1^3;
sbit GREEN_2=P1^4;
sbit RED_3=P1^5;
sbit YELLOW_3=P1^6;
sbit GREEN_3=P1^7;
sbit RED_4=P3^1;
sbit GREEN_4=P3^0;
u8 code smgduan[17]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
u8 DisplayData[8];
u8 second;
void delay(u16 z)
{
while(z--);
}
void DigDisplay()
{
u8 i;
for(i=0; i<8; i++)
{
switch(i)
{
case(0):
LSA=0;LSB=0;LSC=0; break;//显示第0位
case(1):
LSA=1;LSB=0;LSC=0; break;//显示第1位
case(2):
LSA=0;LSB=1;LSC=0; break;//显示第2位
case(3):
LSA=1;LSB=1;LSC=0; break;//显示第3位
case(4):
LSA=0;LSB=0;LSC=1; break;//显示第4位
case(5):
LSA=1;LSB=0;LSC=1; break;//显示第5位
case(6):
LSA=0;LSB=1;LSC=1; break;//显示第6位
case(7):
LSA=1;LSB=1;LSC=1; break;//显示第7位
}
GPIO_dig=DisplayData[i];
delay(100);
GPIO_dig=0x00;
}
}
void Time0Init()
{
TMOD|=0x01;
TH0=0xFC;
TL0=0x18;
EA=1;
ET0=1;
TR0=1;
}
void main()
{
second=1;
Time0Init();
while(1)
{
if(second==70)
{
second=1;
}
if(second < 31)
{
DisplayData[0] = 0x00;
DisplayData[1] = 0x00;
DisplayData[2] = smgduan[(30 - second) % 100 / 10];
DisplayData[3] = smgduan[(30 - second) %10];
DisplayData[4] = 0x00;
DisplayData[5] = 0x00;
DisplayData[6] = DisplayData[2];
DisplayData[7] = DisplayData[3];
DigDisplay();
GPIO_traffic=0xff;
RED_4=1;
GREEN_4=1;
GREEN_2=0;
GREEN_1=0;
RED_3=0;
RED_4=0;
}
else if(second < 36)
{
DisplayData[0] = 0x00;
DisplayData[1] = 0x00;
DisplayData[2] = smgduan[(35 - second) % 100 / 10];
DisplayData[3] = smgduan[(35 - second) %10];
DisplayData[4] = 0x00;
DisplayData[5] = 0x00;
DisplayData[6] = DisplayData[2];
DisplayData[7] = DisplayData[3];
DigDisplay();
GPIO_traffic=0xff;
RED_4=1;
GREEN_4=1;
GREEN_1=0;
YELLOW_2=0;
YELLOW_3=0;
RED_4=0;
}
else if(second < 66)
{
DisplayData[0] = 0x00;
DisplayData[1] = 0x00;
DisplayData[2] = smgduan[(65 - second) % 100 / 10];
DisplayData[3] = smgduan[(65 - second) %10];
DisplayData[4] = 0x00;
DisplayData[5] = 0x00;
DisplayData[6] = DisplayData[2];
DisplayData[7] = DisplayData[3];
DigDisplay();
GPIO_traffic=0xff;
RED_4=1;
GREEN_4=1;
RED_1=0;
RED_2=0;
GREEN_3=0;
GREEN_4=0;
}
else
{
DisplayData[0] = 0x00;
DisplayData[1] = 0x00;
DisplayData[2] = smgduan[(70 - second) % 100 / 10];
DisplayData[3] = smgduan[(70 - second) %10];
DisplayData[4] = 0x00;
DisplayData[5] = 0x00;
DisplayData[6] = DisplayData[2];
DisplayData[7] = DisplayData[3];
DigDisplay();
GPIO_traffic=0xff;
RED_4=1;
GREEN_4=1;
YELLOW_2=0;
RED_1=0;
YELLOW_3=0;
GREEN_4=0;
}
}
}
void Time0() interrupt 1
{
static u16 a;
TH0=0xFC;
TL0=0x18;
a++;
if(a == 1000)
{
a=0;
second ++;
}
}
|
|