Home > other >  The digital frequency meter based on 51 single chip microcomputer main program
The digital frequency meter based on 51 single chip microcomputer main program

Time:11-25

#include
Sbit led0=P2 ^ 6;//shift lights
Sbit led1=P2 ^ 7;
Void delay_ms (int x);
Unsigned char code table []={//value table does not display the decimal digital pipe section
X5b x3f 0, 0 x06, 0, 0 x4f, 0 x66,
X07 x6d 0, 0 x7d, 0, 0 x7f, 0 x6f};
Unsigned char code tablewe []={//show decimal digital section value table
XBF 0, 0 x86, 0 XDB, 0 XCF,
XFD xe6 0, 0 xed, 0, 0 x87,
0 XFF. Zero xef};
Int count1=0;
Int time0=0;
Unsigned char a, b, c, d;
Unsigned long int f=0;
Void main ()
{
TMOD=0 x51;/1 works as 16-bit counter/timer, timer 0 works as a 16-bit timer
TH0=(65536-46080)/256;//timing 50 ms
TL0=(65536-46080)%256;
EA=1;//always interrupt
ET0=1;//0 timer interrupt
TR0=1;//start the timer 0
ET1=1;//timer interrupt 1
IT1=1;//count of setting up the falling edge of the count
TR1=1;//start the counter 1
Led0=1;//
all let two lightsLed1=1;
While (1)
{
If (time0==20)//timing time of 1 s to
{
TR1=0;//close timing counter
TR0=0;
F=count1 * 65536 * 256 + + TH1 TL1;//1 s time falling edge measured signal number, namely frequency
If (f<1000)//if the frequency is less than 1000 hz
{
Led0=0;//Hz shift lights
Led1=1;
While (1)
{
A=f/100;
The P2=0 x8f;//blanking
P0=table [a];//digital tube of one hundred - bit values
The P2=0 x8d;
Delay_ms (1);//delay 1 ms
B=(f % 100)/10;
The P2=0 x8f;
P0=table [b];//digital tube ten values
The P2=0 x8b;
Delay_ms (1);
C=f % 100% 10;
The P2=0 x8f;
P0=table [c];//digital tube bits value
The P2=0 x87;
Delay_ms (1);
}
}
If (f>=1000 & amp; & F<10000)//since 1000 hz, the position of the decimal point, using four digital tube display
{
Led0=1;//KHz shift lights
Led1=0;
While (1)
{
A=f/1000;
The P2=0 x6f;
P0=tablewe [a];//the position of the decimal point in the first
The P2=0 x6e;
Delay_ms (1);
B=(f % 1000)/100;
The P2=0 x6f;
P0=table [b];
The P2=0 x6d;
Delay_ms (1);
C=(f % 1000% 100)/10;
The P2=0 x6f;
P0=table [c];
The P2=0 x6b;
Delay_ms (1);
D=f % 1000% 100% 10;
The P2=0 x6f;
P0=table [d];
The P2=0 x67;
Delay_ms (1);
}
}
If (f>=10000 & amp; & F<100000)
{
While (1)
{
A=f/10000;
The P2=0 x6f;
P0=table [a];
The P2=0 x6e;
Delay_ms (1);
B=(f % 10000)/1000;
The P2=0 x6f;
P0=tablewe [b];//the position of the decimal point in the second
The P2=0 x6d;
Delay_ms (1);
C=f % 10000% 1000/100;
The P2=0 x6f;
P0=table [c];
The P2=0 x6b;
Delay_ms (1);
D=f % 10000% 1000% 100/10;
The P2=0 x6f;
P0=table [d];
The P2=0 x67;
Delay_ms (1);
}
}
If (f>=100000 & amp; & F<1000000)
{
While (1)
{
A=f/100000;
The P2=0 x6f;
P0=table [a];
The P2=0 x6e;
Delay_ms (1);
B=(f % 100000)/10000;
The P2=0 x6f;
P0=table [b];
The P2=0 x6d;
Delay_ms (1);
C=(f % 100000% 10000)/1000;
The P2=0 x6f;
P0=tablewe [c];//the position of the decimal point in the third
The P2=0 x6b;
Delay_ms (1);
D=(f % 100000% 10000% by 1000)/100;
The P2=0 x6f;
P0=table [d];
The P2=0 x67;
Delay_ms (1);
}
}
If (f>=1000000)//beyond the scope of the show
{
While (1)
{
The P2=0 XCF;
P0=0 x7f;
The P2=0 xce;
Delay_ms (1);
The P2=0 XCF;
P0=0 x7f;
The P2=0 XCD;
Delay_ms (1);
The P2=0 XCF;
P0=0 x7f;
The P2=0 XCB;
Delay_ms (1);
The P2=0 XCF;
P0=0 x7f;
The P2=0 xc7;
Delay_ms (1);
}
}
}
}

}


Void exter0 ()//timer interrupt 1 0 interrupt program
{
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
Time0 + +;
}
Void exter1 () interrupt 3//counter 1 interrupt program
{TH1=0;
TL1=0;
count1++;
}
Void delay_ms (int x)//delay 1 ms program
{
Unsigned int I;
unsigned char j;
for(i=0; i{
for(j=0; J<200; j++);
for(j=0; J<102; j++);
}
}

CodePudding user response:

Have need schematic diagram of the Q me
  • Related