用at89c51做的频率计 但是检测的结果和实际的相差太大 2倍还多呢 程序如下 有人帮我看看怎么回事 #include <reg51.h> unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90,0xff,}; unsigned char dispbuf[6]={0,0,0,0,10,10}; unsigned char temp[6]; unsigned char dispcount; unsigned char t0count; unsigned char timecount; bit flag; unsigned long x; void main(void) { unsigned char i; TMOD=0x15; TH0=0; TL0=0; TH1=(65536-4000)/256; TL1=(65536-4000)%256; TR1=1; TR0=1; ET0=1; ET1=1; EA=1; while(1) { if(flag==1) { flag=0; x=t0count*65536+TH0*256+TL0; for(i=0;i<6;i++) { temp=0; } i=0; while(x/10) { temp=x%10; x=x/10; i++; } temp=x; for(i=0;i<6;i++) { dispbuf=temp; } timecount=0; t0count=0; TH0=0; TL0=0; TR0=1; } } } void t0(void) interrupt 1 using 0 { t0count++; } void t1(void) interrupt 3 using 0 { TH1=(65536-4000)/256; TL1=(65536-4000)%256; timecount++; if(timecount==250) { TR0=0; timecount=0; flag=1; } P0=dispcode[dispbuf][dispcount]]; P2=dispbit[dispcount]; dispcount++; if(dispcount==6) { dispcount=0; } } 实验板上的频率发生装置用的是74HC4060 |