#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit cs1=P3^5;sbit cs2=P3^6;sbit wr=P3^7;
void delay(uint i){while(i--);}
uchar code ledcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar buf[8];
#define leddata P0
uchar c=0,t;
uchar min=0,sec=0;
void display(void)
{
uchar i,j=0x7f;
for(i=0;i<8;i++)
{
cs1=0;cs2=1;
leddata=ledcode[buf[i]];wr=1;wr=0;
cs1=1;cs2=0;
leddata=j;wr=1;wr=0;
delay(100);
j=_cror_(j,1);
leddata=0xff;wr=1;wr=0;
}
}
void led()
{
P2=0x3f;delay(50000);
P2=0x0f;delay(50000);
P2=0x03;delay(50000);
P2=0x00;delay(50000);
P2=0xc0;delay(50000);
P2=0xf0;delay(50000);
P2=0xfc;delay(50000);
P2=0xff;delay(50000);
}
void main()
{
TMOD=0x11;
EA=ET0=TR0=1;
while(1)
{
buf[0]=buf[1]=buf[2]=buf[3]=0xff;
buf[4]=min/10%10;
buf[5]=min%10;
buf[6]=sec/10%10;
buf[7]=sec%10;
display();
led();
//if(sec>5&&min>=0)led();
}
}
time0() interrupt 1
{
TL0=(65536-50000)%256;
TH0=(65536-50000)/256;
c++;
if(c>=20)
{
c=0;sec++;
if(sec>=60)
{
sec=0;
min++;
if(min>=60)
{
min=0;
}
}
}
}
|