|
#include<reg51.h>
unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit LED0=P1^0;
sbit LED1=P1^1;
unsigned char n,sec;
void delay(unsigned char i)
{
unsigned char j;
while(i--);
{
for(j=0;j<125;j++)
{;}
}
}
void display()
{
P2=0x01;
P0=tab[sec/10];
delay(3);
P2=0x02;
P0=tab[sec%10];
delay(3);
}
void main()
{
sec=00;
TMOD=0x01; //选择T0,于工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
EA=1;
ET0=1;
n=0;
LED0=0;
LED1=1;
while(1)
{
display();
}
}
void timer() interrupt 1
{
n++;
if(n==20)
{
n=0;
sec++;
if(sec==60)
{
sec=0;
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
|
|