#include<reg52.h>
sbit P3_5=P3^5;
sbit du=P2^6;
sbit we=P2^7;
unsigned char i=0,j=0,z=0;
unsigned code table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code wei[]={0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void init_
timer(void)
{
TMOD |=0x61;
TH0=0x3c;
TL0=0xb0;
TH1=0xf6;
TL1=0xf6;
EA=1;
ET0=1;ET1=1;
TR0=1;TR1=1;//定时器0计数器1初始化
}
void delay(unsigned int t)
{
unsigned int n;
unsigned char j;
for(n=t;n>0;n--)
for(j=110;j>0;j--);
}
void display()
{
unsigned int scon1,scon2,min1,min2,hou1,hou2;
scon1=i%10; du=1;P0=table[scon1];du=0; we=1;P0=0xdf;we=0; delay(4);
scon2=i/10; du=1;P0=table[scon2];du=0; we=1;P0=0xef;we=0; delay(4);
min1=j%10; du=1;P0=table[min1]|0x80;du=0; we=1;P0=0xf7;we=0; delay(4);
min2=j/10; du=1;P0=table[min2];du=0; we=1;P0=0xfb;we=0; delay(4);
hou1=z%10; du=1;P0=table[hou1]|0x80;du=0; we=1;P0=0xfd;we=0; delay(4);
hou2=z/10; du=1;P0=table[hou2];du=0; we=1;P0=0xfe;we=0; delay(4);
}
void main()
{
init_Timer();
while(1)
{
display();
}
}
void Timer0_isr(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
P3_5=!P3_5;
}
void Timer1_isr(void) interrupt 3
{
i++;
if(i>59){i=0;j++;}
if(j>59){j=0;z++;}
if(z>23)z=0;
自己算的,算了好多次的应该没错
这个有道理,有什么解决的方法么?
一周热门 更多>