📄 第六节:低频频率计.mht
字号:
=BB=B9=CA=E4=C8=EB=B5=BDINT1=A3=A8P3.3=A3=A9=A1=A3<BR>
<P></P>
<DIV class=3DcodeText>
<DIV class=3DcodeHead>=B4=FA=C2=EB</DIV>
<OL class=3Ddp-cpp>
<LI class=3Dalt><SPAN><SPAN>unsigned </SPAN><SPAN=20
=
class=3Ddatatypes>int</SPAN><SPAN> us100; </SPAN><S=
PAN=20
=
class=3Dcomment>//=B6=D4100us=CA=B1=BC=E4=BC=E4=B8=F4=B5=A5=CE=BB=BC=C6=CA=
=FD=A3=AC=BC=B4=D3=D0=B6=E0=C9=D9=B8=F6100us=A1=A3=20
</SPAN><SPAN> </SPAN></SPAN>=20
<LI class=3D""><SPAN>unsigned </SPAN><SPAN=20
class=3Ddatatypes>char</SPAN><SPAN> Second; </SPAN>=20
<LI class=3Dalt><SPAN>unsigned </SPAN><SPAN=20
=
class=3Ddatatypes>int</SPAN><SPAN> K64; </SPA=
N><SPAN=20
=
class=3Dcomment>//=B6=D464K=B5=A5=CE=BB=BC=C6=CA=FD=A3=AC=BC=B4=D3=D0=B6=E0=
=C9=D9=B8=F664K </SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN>unsigned </SPAN><SPAN=20
class=3Ddatatypes>char</SPAN><SPAN> oldT0; </SPAN>=20
<LI class=3Dalt><SPAN>unsigned </SPAN><SPAN=20
=
class=3Ddatatypes>int</SPAN><SPAN> oldus, oldK64, oldT1;=20
</SPAN>=20
<LI class=3D""><SPAN>unsigned </SPAN><SPAN=20
=
class=3Ddatatypes>long</SPAN><SPAN> fcy; </SP=
AN><SPAN=20
=
class=3Dcomment>//=B4=E6=B7=C5=C6=B5=C2=CA=D6=B5=A3=AC=B5=A5=CE=BB=CE=AAH=
z </SPAN><SPAN> </SPAN>=20
<LI =
class=3Dalt><SPAN>bit HighLow=3D1; </SPAN><SP=
AN=20
=
class=3Dcomment>//1=A3=BA=B1=ED=CA=BE=D0=C5=BA=C5=B3=AC=B9=FD1KHz=A3=BB0=A3=
=BA=B1=ED=CA=BE=D0=C5=BA=C5=B5=CD=D3=DA1KHz=A1=A3 =
</SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN class=3Dkeyword>void</=20
span><SPAN> InitialHigh( </SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> ) </SPAN>=20
<LI class=3Dalt><SPAN>{ </SPAN>=20
<LI class=3D""><SPAN> IE=3D0; IP=3D0; HighLow=3D1; =
</SPAN>=20
<LI=20
=
class=3Dalt><SPAN>TMOD =3D (TMOD & 0xf0) |&n=
bsp;0x02; TH0=3D-200; TL0=3DTH0; PX0=3D1; T0=3D1;&nbs=
p;=20
</SPAN>=20
<LI=20
=
class=3D""><SPAN> TMOD =3D (TMOD & 0x0f)&nbs=
p;| 0x50; TH1=3D0; TL1=3D0; T1=3D1; ET1=3D1;=20
</SPAN>=20
<LI class=3Dalt><SPAN> Us100=3D0; Second=3D0; K64=3D0;=20
</SPAN>=20
<LI class=3D""><SPAN> oldK64=3D0; oldT1=3D0; =
</SPAN>=20
<LI =
class=3Dalt><SPAN> TCON |=3D 0x50; </SPAN><SPAN=
=20
class=3Dcomment>//=CD=AC=CA=B1=D6=C3 TR0=3D1; TR1=3D1; =
</SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN> EA =3D 1; </SPAN>=20
<LI class=3Dalt><SPAN>} </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> InitialLow( </SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> ) </SPAN>=20
<LI class=3Dalt><SPAN>{ </SPAN>=20
<LI class=3D""><SPAN> IE=3D0; IP=3D0; HighLow=3D0; =
</SPAN>=20
<LI=20
=
class=3Dalt><SPAN>TMOD =3D (TMOD & 0xf0) |&n=
bsp;0x02; TH0=3D-200; TL0=3DTH0; ET0=3D1; TR0=3D1;=20
</SPAN>=20
<LI =
class=3D""><SPAN> INT1 =3D 1; IT1=3D1; EX1=3D1; =
</SPAN>=20
<LI class=3Dalt><SPAN> Us100=3D0; Second=3D0; K64=3D0;=20
</SPAN>=20
<LI class=3D""><SPAN> oldK64=3D0; oldT1=3D0; =
</SPAN>=20
<LI class=3Dalt><SPAN> EA =3D 1; </SPAN>=20
<LI class=3D""><SPAN>} </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> T0intr( </SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> ) interrupt 1=20
</SPAN>=20
<LI class=3D""><SPAN>{ </SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( HighLow=3D=3D0 ) ++us100;=
=20
</SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>else</SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( ++us100 >=3D 10000&nbs=
p;)=20
</SPAN>=20
<LI class=3Dalt><SPAN>{ unsigned </SPAN><SPAN=20
class=3Ddatatypes>int</SPAN><SPAN> tmp1, tmp2; =
</SPAN>=20
<LI=20
=
class=3D""><SPAN>TR1=3D0; tmp1=3D(TH1<<8) + (TL1);&n=
bsp;tmp2=3DK64; TR1=3D1;=20
</SPAN>=20
<LI =
class=3Dalt><SPAN>fcy=3D((tmp2-oldK64)<<16) + (tmp1-oldT1=
);=20
</SPAN>=20
<LI class=3D""><SPAN>oldK64=3Dtmp1; oldT1=3Dtmp2; =
</SPAN>=20
<LI class=3Dalt><SPAN>Second++; </SPAN>=20
<LI class=3D""><SPAN>us100=3D0; </SPAN>=20
<LI class=3Dalt><SPAN>} </SPAN>=20
<LI class=3D""><SPAN>} </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> T1intr( </SPAN><SPAN=20
=
class=3Dkeyword>void</SPAN><SPAN> ) interrupt 3 {&nbs=
p;++K64; }=20
</SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> X1intr( </SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> ) interrupt 2=20
</SPAN>=20
<LI class=3Dalt><SPAN>{ </SPAN><SPAN=20
class=3Dkeyword>static</SPAN><SPAN> unsigned </SPAN><SPAN=20
class=3Ddatatypes>char</SPAN><SPAN> sts=3D0; </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
class=3Dkeyword>switch</SPAN><SPAN>( sts ) =
</SPAN>=20
<LI class=3Dalt><SPAN>{ </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
=
class=3Dkeyword>case</SPAN><SPAN> 0: sts =3D 1; =
</SPAN><SPAN=20
class=3Dkeyword>break</SPAN><SPAN>; </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
=
class=3Dkeyword>case</SPAN><SPAN> 1: oldT0=3DTL0; oldus=3D=
us100; sts=3D2; </SPAN><SPAN=20
class=3Dkeyword>break</SPAN><SPAN>; </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN =
class=3Dkeyword>case</SPAN><SPAN> 2: =20
</SPAN>=20
<LI class=3Dalt><SPAN>{ </SPAN>=20
<LI class=3D""><SPAN> unsigned </SPAN><SPAN=20
class=3Ddatatypes>char</SPAN><SPAN> tmp1, tmp2; =
</SPAN>=20
<LI =
class=3Dalt><SPAN> TR0=3D0; tmp1=3DTL0; tmp2=3Dus100; =
;TR0=3D1;=20
</SPAN>=20
<LI=20
=
class=3D""><SPAN> fcy =3D 1000000L/( (tmp2-oldus)*100=
L + (256-tmp1)/2 );=20
</SPAN>=20
<LI class=3Dalt><SPAN> Second ++; </SPAN>=20
<LI class=3D""><SPAN>} </SPAN>=20
<LI class=3Dalt><SPAN> Sts =3D 0; </SPAN>=20
<LI class=3D""><SPAN> </SPAN><SPAN =
class=3Dkeyword>break</SPAN><SPAN>;=20
</SPAN>=20
<LI class=3Dalt><SPAN> } </SPAN>=20
<LI class=3D""><SPAN>} </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> main( </SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> ) </SPAN>=20
<LI class=3D""><SPAN>{ </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( HighLow=3D=3D1) InitialHigh();=
</SPAN><SPAN=20
class=3Dkeyword>else</SPAN><SPAN> InitialLow(); =
</SPAN>=20
<LI class=3D""><SPAN> While(1) </SPAN>=20
<LI class=3Dalt><SPAN> { </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
class=3Dkeyword>if</SPAN><SPAN>( Second !=3D 0 )=20
</SPAN>=20
<LI class=3Dalt><SPAN>{ </SPAN>=20
<LI class=3D""><SPAN>Second =3D 0; </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
=
class=3Dcomment>//display fcy =D2=FD=D3=C3=C7=B0=C3=E6=B5=
=C4=CA=FD=C2=EB=B9=DC=C7=FD=B6=AF=B3=CC=D0=F2=A3=AC=D7=A2=D2=E2=CF=C2=C3=E6=
=B6=D4T0=D6=D0=B6=CF=B7=FE=CE=F1=B3=CC=D0=F2=B5=C4=D0=DE=B8=C4=20
</SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN>{ unsigned </SPAN><SPAN=20
class=3Ddatatypes>char</SPAN><SPAN> i; </SPAN>=20
<LI class=3Dalt><SPAN> </SPAN><SPAN=20
=
class=3Dkeyword>for</SPAN><SPAN>( i=3D0; i<8; i++ =
){ Display(i, fcy%10); fcy /=3D 10; }=20
</SPAN>=20
<LI class=3D""><SPAN>} </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>if</SPAN><SPAN>( HighLow=3D=3D1 ) =
</SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( fcy<1000L ){ InitalLow=
();} =20
</SPAN>=20
<LI class=3Dalt><SPAN> </SPAN><SPAN=20
class=3Dkeyword>else</SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN> </SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( fcy>1000L ){ InitalHig=
h();}=20
</SPAN>=20
<LI class=3Dalt><SPAN>} </SPAN>=20
<LI class=3D""><SPAN> } </SPAN>=20
<LI class=3Dalt><SPAN>} </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
=
class=3Dcomment>//=D0=DE=B8=C4T0=B5=C4=D6=D0=B6=CF=B7=FE=CE=F1=B3=CC=D0=F2=
=A3=AC=C8=C3=CB=FC=D4=DA=CD=EA=B3=C9=CA=B1=B1=EA=B5=C4=B9=A6=C4=DC=CA=B1=A3=
=AC=CD=AC=CA=B1=CD=EA=B3=C9=CA=FD=C2=EB=B9=DC=CF=D4=CA=BE=CB=A2=D0=C2=20
</SPAN><SPAN> </SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> T0intr( </SPAN><SPAN=20
class=3Dkeyword>void</SPAN><SPAN> ) interrupt 1=20
</SPAN>=20
<LI class=3D""><SPAN>{ </SPAN>=20
<LI class=3Dalt><SPAN> </SPAN><SPAN=20
class=3Dkeyword>static</SPAN><SPAN> unsigned </SPAN><SPAN=20
class=3Ddatatypes>char</SPAN><SPAN> ms =3D 0; =
</SPAN>=20
<LI class=3D""><SPAN> </SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( HighLow=3D=3D0 ) ++us100;=
=20
</SPAN>=20
<LI class=3Dalt><SPAN></SPAN><SPAN=20
class=3Dkeyword>else</SPAN><SPAN> </SPAN>=20
<LI class=3D""><SPAN></SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( ++us100 >=3D 10000&nbs=
p;)=20
</SPAN>=20
<LI class=3Dalt><SPAN>{ unsigned </SPAN><SPAN=20
class=3Ddatatypes>int</SPAN><SPAN> tmp1, tmp2; =
</SPAN>=20
<LI=20
=
class=3D""><SPAN>TR1=3D0; tmp1=3D(TH1<<8) + (TL1);&n=
bsp;tmp2=3DK64; TR1=3D1;=20
</SPAN>=20
<LI =
class=3Dalt><SPAN>fcy=3D((tmp2-oldK64)<<16) + (tmp1-oldT1=
);=20
</SPAN>=20
<LI class=3D""><SPAN>oldK64=3Dtmp1; oldT1=3Dtmp2; =
</SPAN>=20
<LI class=3Dalt><SPAN>Second++; </SPAN>=20
<LI class=3D""><SPAN>us100=3D0; </SPAN>=20
<LI class=3Dalt><SPAN>} </SPAN>=20
<LI class=3D""><SPAN> </SPAN><SPAN=20
=
class=3Dkeyword>if</SPAN><SPAN>( ++ms >=3D 10 ){&n=
bsp;ms=3D0; DisplayBrush(); } </SPAN><SPAN=20
class=3Dcomment>//1ms=CA=FD=C2=EB=B9=DC=CB=A2=D0=C2 =
</SPAN><SPAN> </SPAN>=20
<LI class=3Dalt><SPAN>} </SPAN> </LI></OL></DIV>
<P><BR><BR> </P></DIV>
<DIV class=3Dpagebreak>=B9=B29=D2=B3: <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_6.html">=C9=
=CF=D2=BB=D2=B3</A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945.html">1</A=
> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_2.html">2<=
/A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_3.html">3<=
/A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_4.html">4<=
/A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_5.html">5<=
/A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_6.html">6<=
/A>=20
<STRONG>7</STRONG><A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_8.html">8<=
/A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_9.html">9<=
/A> <A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2945_8.html">=CF=
=C2=D2=BB=D2=B3</A>=20
</DIV>
<DIV class=3Dtext_tag>
<H5>Tags=A3=BA<B><B><A =
href=3D"http://www.dzkf.cn/tag.php?/Keil/">Keil</A></B> =20
<B><A =
href=3D"http://www.dzkf.cn/tag.php?/51%B5%A5%C6%AC%BB%FA/">51=B5=A5=C6=AC=
=BB=FA</A></B>=20
</B> </H5>
<LI style=3D"DISPLAY: none"></LI></DIV>
<DIV class=3Dxg>
<LI>=C9=CF=D2=BB=C6=AA=A3=BA<A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0108/2944.html">uCOS=
=20
II=BE=CD=D0=F7=B1=ED=A3=A8Ready List=A3=A9=B7=D6=CE=F6</A> </LI>
<LI>=CF=C2=D2=BB=C6=AA=A3=BA<A=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2008/0121/2967.html">Wind=
ows CE=20
OAL=B2=E3=B5=C4=BD=E1=B9=B9=D3=EB=BF=AA=B7=A2</A> </LI>
<LI>=A1=A4<A =
title=3D=B5=A5=C6=AC=BB=FA=CF=B5=CD=B3=D6=D0PS/2=BC=FC=C5=CC=C7=FD=B6=AF=B3=
=CC=D0=F2=B5=C4=C9=E8=BC=C6=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2007/0924/2619.html">=B5=A5=
=C6=AC=BB=FA=CF=B5=CD=B3=D6=D0PS/2=BC=FC=C5=CC=C7=FD=B6=AF=B3=CC=D0=F2=B5=
=C4=C9=E8=BC=C6</A>=20
</LI>
<LI>=A1=A4<A title=3D"Keil =
C51=B6=D4=CD=AC=D2=BB=B6=CB=BF=DA=B5=C4=C1=AC=D0=F8=B6=C1=C8=A1=B7=BD=B7=A8=
"=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2007/0810/2480.html">Keil=
=20
C51=B6=D4=CD=AC=D2=BB=B6=CB=BF=DA=B5=C4=C1=AC=D0=F8=B6=C1=C8=A1=B7=BD=B7=A8=
</A> </LI>
<LI>=A1=A4<A =
title=3D51=B5=A5=C6=AC=BB=FA=B2=D9=D7=F7=CF=B5=CD=B3=BF=AA=B7=A2=D6=D0=B5=
=C4=CE=CA=CC=E2=D3=EB=BC=BC=C7=C9=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2006/0919/657.html">51=B5=
=A5=C6=AC=BB=FA=B2=D9=D7=F7=CF=B5=CD=B3=BF=AA=B7=A2=D6=D0=B5=C4=CE=CA=CC=E2=
=D3=EB=BC=BC=C7=C9</A>=20
</LI>
<LI>=A1=A4<A =
title=3DSPI=D7=DC=CF=DF=D4=DA51=B5=A5=C6=AC=BB=FA=CF=B5=CD=B3=D6=D0=B5=C4=
=CA=B5=CF=D6=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2009/0112/3605.html">SPI=D7=
=DC=CF=DF=D4=DA51=B5=A5=C6=AC=BB=FA=CF=B5=CD=B3=D6=D0=B5=C4=CA=B5=CF=D6</=
A>=20
</LI>
<LI>=A1=A4<A =
title=3D=D0=A1=C8=DD=C1=BF=B5=A5=C6=AC=BB=FA=CF=B5=CD=B3=B5=C4C=D3=EF=D1=D4=
=B3=CC=D0=F2=BD=E1=B9=B9=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2007/0619/2260.html">=D0=A1=
=C8=DD=C1=BF=B5=A5=C6=AC=BB=FA=CF=B5=CD=B3=B5=C4C=D3=EF=D1=D4=B3=CC=D0=F2=
=BD=E1=B9=B9</A>=20
</LI>
<LI>=A1=A4<A title=3D"Keil C51=B3=F5=CA=BC=BB=AF=B4=FA=C2=EB =
Startup.a51=B5=C4=D6=D0=CE=C4=CB=B5=C3=F7"=20
href=3D"http://www.dzkf.cn/html/qianrushixitong/2007/0104/1333.html">Keil=
C51=B3=F5=CA=BC=BB=AF=B4=FA=C2=EB=20
Startup.a51=B5=C4=D6=D0=CE=C4=CB=B5=C3=F7</A> </
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -