各位大师,我最近在学动态显示,用的是两位的数码管写了一个0到99的程序,可是仿真起来,数字变化太快,请问应该怎么解决,是直接定时一秒吗?程序如下:#include<at89x52.h>
#include<intrins.h>
char code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};/*共阴数码管*/
unsigned char data led[]={0,0};/*用两个LED定义成一个数组,用来显示个位和十位*/
char code num1[]={0xfd,0xfe};
#define uint unsigned int
#define uchar unsigned char
uint count;
bit flag;
char tt;
void delay(uint x)
{
uchar i;
while(x--)
{
for(i=120;i>0;i--);
}
}
void show()
{
uint i;
led[1]=count/10;
led[0]=count%10;
if(led[1]>9)led[1]=led[1]-10;
if(led[1]==0)
{led[1]=0x0a;}
for(i=0;i<2;i++)
{
P0=num1[i];
P1=num[led[i]];
delay(20);
}
}
int time0()interrupt 1/*不能用UINT*/
{
char time=0;
TH0=-100000/256;
TL0=-100000%256;
count++;
delay(20);
}
int main()
{
TMOD=0X01;
TH0=-100000/256;
TL0=-100000%256;
TR0=1;
EA=1;
ET0=1;
/* delay(100);*/
while(1)
{
show();/*必须要,不要显示不了*/
}
} |