低频计(0.00~99.99HZ)加入信号后一直显示0,希望大手给力

2019-03-24 19:40发布

低频计(0.00~99.99HZ)加入信号后一直显示0,希望大手给力贴代码,少废话//外部信号输入到INT1端口#include<reg52.h>#define uchar unsigned char#define uint unsigned int#define ulong unsigned longuint us100;     //对100us时间间隔单位计数,既有多少个100usuchar old_t0;     //外部频率输入时的T0值uchar old_us100;     //外部频率输入时的us100ulong f;     //存放频率值,单位HZuint qian,bai,shi,ge;uchar flag;     //标志位double f_temple; uchar code f_table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(uint z){ uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); }
void display(uint qian,uchar bai,uchar shi,uchar ge){ P2=0X01; P0=f_table[qian]; delay(5);
P2=0X02; P0=f_table[bai]+0x80; delay(5);
P2=0X04; P0=f_table[shi]; delay(5);
P0=0X08; P0=f_table[ge]; delay(5);} 
void init(){ TMOD=0X02; TH0=-100; TL0=-100; ET0=1; TR0=1; IT1=1; EX1=1; us100=0; flag=0; old_t0=0; old_us100=0; f_temple=0; f=0; EA=1;}
void t0_intr() interrupt 1{ us100++;}
void x1_intr() interrupt 2{ static uchar sts=0; uchar temp1,temp2; switch(sts) { case 0: sts=1; break; case 1: sts=2; TR0=0; old_t0=TL0; old_us100=us100; TR0=1; break; case 11: { TR0=0; temp1=TL0; temp2=us100; f_temple=(double)1000000/((temp2-old_us100)*100+(temp1-old_t0))/10; f=(ulong)f_temple*100; flag++; qian=f/1000; bai=f%1000/100; shi=f%100/10; ge=f%10;    TR0=1; } sts=0; break; } }
void main(){ init(); while(1) { if(flag!=0) { flag=0; display(qian,bai,shi,ge); } }}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。