博主福利:100G+电子设计学习资源包!
http://mp.weixin.qq.com/mp/homepage?__biz=MzU3OTczMzk5Mg==&hid=7&sn=ad5d5d0f15df84f4a92ebf72f88d4ee8&scene=18#wechat_redirect
--------------------------------------------------------------------------------------------------------------------------
频率测量方法:
- 测频法:测试限定时间内检测脉冲的个数(1s)
- 测周法:采样N个脉冲所使用的时间
测频法实验:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
设计要求:
通过测频法测出时钟发生器的频率并显示在显示屏上
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
实现过程:
通过DCLOCK时钟发生器产生时钟频率,如下图所示,一秒钟产生233个频率
T0接收时钟发生器产生的脉冲,使用count变量计数,定时器T1完成1s后关闭中断,并将此时的count显示出来
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
元件清单:
- AT89C51
- 7SEG-MPX8-CC-BLUE
- DCLOCK(在电压探针列表中)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
实现代码:
#include
typedef unsigned int uint;
typedef unsigned char uchar;
uchar code number[] =
{0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E
};
uchar code address[] =
{0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F
};
uint count = 0, time = 0, temp; //一定要用int类型,char类型只有8位,计数只到255
bit flag = 0;
void Delay(uchar m)
{while(--m);
}
int main()
{uchar i;EA &#61; 1;ET0 &#61; 1;ET1 &#61; 1;TMOD &#61; 0x16; //定时器1为方式1,计数器0为方式2,T0选择C/T&#61;1,计数器方式,脉冲由外部提供TH0 &#61; 0xff;TL0 &#61; 0xff;TR0 &#61; 1;TH1 &#61; (65536 - 50000) / 256;TL1 &#61; (65536 - 50000) % 256;TR1 &#61; 1;while(1){if (flag &#61;&#61; 1){temp &#61; count;for (i &#61; 0; i <8; &#43;&#43;i){P2 &#61; address[i];P1 &#61; number[temp % 10];temp &#61; temp / 10;Delay(500);}}}
}
void Count0()interrupt 1
{&#43;&#43;count;
}
void Time1()interrupt 3
{TH1 &#61; (65536 - 50000) / 256;TL1 &#61; (65536 - 50000) % 256;&#43;&#43;time;if (time &#61;&#61; 20){EA &#61; 0;flag &#61; 1;}
}