感谢两位的回复。再请帮我看看我的程序,频率测不准,差太远了,lm311组成的电路用示波器测工作416k,按下cal后为305k,而用2051测的只有15k左右,按下cal后为反而频率更大为120k
#include<at892051.h>
#include<stdio.h>
#define s2 p1_4
#define s3 p1_3
unsigned char timer0_count;
void timer0()interrupt 1 using 3
{
timer0_count++;
}
void delay(unsigned char ms)
{
unsigned char i;
while(ms-- !=0)
{
for(i=0;i<114;i++)
;
}
}
unsigned long freq()
{
unsigned char temp1;
unsigned char temp2;
unsigned char temp3;
unsigned long freq;
tr0=1;//
delay(250);//
delay(250);//
delay(250);//
delay(250);//
tr0=0;//
temp1=timer0_count;
temp2=th0;
temp3=tl0;
timer0_count=0;
th0=0;
tl0=0;
freq=temp1*65536;
freq=freq+temp2*256;
freq=freq+temp3;
return freq;
}
void init()
{
ea=0;
tmod=0x25;
th0=0;
tl0=0;
scon=0x50;
th1=0xfd;
tr1=1;
ti=1;
ea=1;
}
//
main()
{
unsigned long f2;//
init();
while(1)
{
if(s2==0)
{
f2=freq();
printf("jz%lu,",f2);
}
else
{
if(s3==0)
{
f2=freq();
printf("cx%lu,",f2);
}
else
{
f2=freq();
printf("lx%lu,",f2);
}
}
}
}