#include <reg51.h>
unsigned int time ;
char code tap[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//数码管0-9
void dingshidaojishi();
sbit H=P0^2;
sbit L=P0^3;
unsigned char miao=60;
unsigned char feng=30;
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x0D8;
TL0 = 0x0F0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void delay1ms(void) //误差 0us
{
unsigned char a,b;
for(b=199;b>0;b--)
for(a=1;a>0;a--);
}
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x0D8;
TL0 = 0x0F0;
time++;
}
void main ()
{
unsigned char flag=0;
// P1=0xc0;
// P0=0x00;
InitTimer0();
while(1)
{
dingshidaojishi();
if(time==50)
{
time=0;
if(flag==0)
{
flag=1;
P1=feng;
}
else
{
flag=0;
P1=feng(~(1<<7));
miao--;
}
if(miao==0)
{
miao=60;
feng--;
}
}
}
}
void dingshidaojishi()
{
H=1;
P1=(tap[feng/10]);
delay1ms();
H=0;
L=1;
P1=(tap[feng%10]);
delay1ms();
L=0;
delay1ms();
}
|