#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar f,pulse,t;
bit flat;
uint dis[3];
uchar con[]={0xfe,0xfd,0xfb,0xf7};
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit dula=P2^0;
sbit wela=P2^1;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=50;y>0;y--);
}
void ini()
{
EA=1;
EX0=1;
ET0=1;
IT0=1;
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
TR0=1;
}
void calcu()
{
dis[0]=f/1000;
dis[1]=f%1000/100;
dis[2]=f%100/10;
dis[3]=f%10;
}
void display()
{
uchar i;
for (i=0;i<4;i++)
{
P0=con[i];
wela=1;
wela=0;
P0=table[dis[i]];
dula=1;
dula=0;
delay(10);
}
}
void main()
{
ini();
while (1)
{
calcu();
display();
}
}
void int0() interrupt 0
{
pulse++;
if (flat==1)
{
flat=0;
f=pulse;
pulse=0;
}
}
void
tim0() interrupt 1
{
TR0=0;
TH0=0x3c;
TL0=0xb0;
t++;
if (t==20)
{
flat=1;
}
TR0=1;
}
最后
仿真不出来结果,显示为0是为什么???
-
proteus仿真
1002925094
一周热门 更多>