#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar data_L,data_H;
uchar t,a;
void delay(uint k)
{
uint m,n;
for(m=0;m<k;m++)
{
for(n=0;n<120;n++);
}
}
void display (void)
{
P2=0x01;
P0=tab[data_H];
delay(1);
P2=0x02;
P0=tab[data_L];
delay(1);
}
void Timer0() interrupt 1
{
t++;
TH0=0x4c;
TL0=0x00;
}
void data_tim(void)
{
if(t==20)
{
a++;
t=0;
if(a==60)
{
a=0;
}
}
}
void data_in(void)
{
data_L=a%10;
data_H=a/10;
}
void T0_init(void)
{
TMOD=0x01;
TH0=0x4C;
TL0=0x00;
ET0=1;
TR0=1;
EA=1;
}
void main(void)
{
a=0;
T0_init();
while(1)
{
data_tim();
data_in();
display();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)