27,509
社区成员




#include <reg52.h>
#define LED P1
#define DATA P0
sbit LATCH1 = P2^2;
sbit LATCH2 = P2^3;
unsigned char DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char WeiMa[2]={0xfe,0xfd};
void delay(unsigned char t);
void time(unsigned char t);
void display(unsigned char t);
unsigned char tempdata[2];
void main(void)
{
while(1)
{
LED = 0xfc; //红灯
display(60);
LED = 0xF3; //黄灯
display(5);
LED = 0xCF; //绿灯
display(50);
}
}
void delay(unsigned char t)
{
while(--t);
}
void time(unsigned char t)
{
tempdata[0] = DuanMa[t/10];
tempdata[1] = DuanMa[t%10];
}
void display(unsigned char t)
{
unsigned char i;
while(t)
{
time(t);
for (i = 0 ; i < 2 ; i++)
{
DATA = 0;
LATCH2 = 1;
LATCH2 = 0;
DATA = WeiMa[i];
LATCH1 = 1;
LATCH1 = 0;
DATA = tempdata[i];
LATCH2 = 1;
LATCH2 = 0;
delay(2000);
}
t--;
delay(50000); //随便弄得时间,为了观察变化
}
}