#include<reg52.h>
sbit latch1=P2^1;
sbit latch2=P2^2;
void delay(unsigned int t);
unsigned char weima[8]=
{0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char duanma[10]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char LED[]={0xcf,0xf3,0xfc,0xf3};
unsigned char tempdata[10];
void delay(unsigned int t);
void display(unsigned char firstbite,unsigned char num);
main(void)
{
unsigned int m=30,n,i=0;
P1=0xcf;
TMOD=0x10;
TH1=0x3c;
TL1=0xb0;
TR1=1;
while(1)
{
if(TF1==1)
{
TF1=0;
n++;
TH1=0x3c;
TL1=0xb0;
if(n==20)
{
n=0;
if(m>0) m--;
if(m==0)
{
i++;
P1=LED[i];
if(i==3)i=0;
m=30;
}
}
}
tempdata[0]=duanma[m/10];
tempdata[1]=duanma[m%10];
display(3,2);
}
}
void delay(unsigned int t)
{
while(t--);
}
void display(unsigned char firstbite,unsigned char num)
{
unsigned int i;
for(i=0;i<num;i++)
{
P0=0;
latch2=1;
latch2=0;
P0=weima[i+firstbite];
latch1=1;
latch1=0;
P0=tempdata[i];
latch2=1;
latch2=0;
delay(200);
}
}
这个程序的定时不准 我本来定的间隔是1s 结果运行时是1.04s左右,通过改初值也无法精确到一秒,总会多或少0.0几秒,请高手给看看是怎么回事?晶振是12MHZ的 谢谢 |