原理简单,附有源程序,同时能够直接仿真看结果。可以测试三角波,正弦波等,同时测量1-100khz。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载):
单片机源程序如下:
- /********************************************************************
- 汇诚科技
- 网址:http://www.ourhc.cn
- 产品有售淘宝店:http://shop36330473.taobao.com
- *********************************************************************/
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar duan[10]={0xc0,0Xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //所需的段的位码
- //uchar wei[4]={0XEf,0XDf,0XBf,0X7f}; //位的控制端 (开发板)
- uchar wei[4]={0X80,0X40,0X20,0X10}; //位的控制端 (仿真)
- uint z,x,c,v, date; //定义数据类型
- uint dispcount=0;
- uint lck=0;
- uint disp=0;
- /******************************************************************
- 延时函数
- ******************************************************************/
- void delay(uchar t)
- {
- uchar i,j;
- for(i=0;i<t;i++)
- {
- for(j=13;j>0;j--);
- { ;
- }
- }
- }
- /**********************************************************************
- 数码管动态扫描
- *********************************************************************/
- void xianshi()
- {
- /*****************数据转换*****************************/
- z=date/1000; //求千位
- x=date%1000/100; //求百位
- c=date%100/10; //求十位
- v=date%10; //求个位
- P2=wei[0];
- P0=duan[z];
- delay(50);
- P2=wei[1];
- P0=duan[x];
- delay(50);
- P2=wei[2];
- P0=duan[c];
- delay(50);
- P2=wei[3];
- P0=duan[v];
- delay(50);
-
- }
- /*************************************************************************
- 定时器初值1ms
- **************************************************************************/
- void initTimer(void)
- {
- TMOD=0x0;
- TH0=0xe3;
- TL0=0xc;
- }
- /*************************************************************************
- 定时器函数
- **************************************************************************/
- void timer0(void) interrupt 1
- {
- TH0=0xe3;
- TL0=0xc;
- lck++;
- if(lck==1000)
- {
- disp=dispcount;
- lck=0;
- dispcount=0;
- }
- }
- /*************************************************************************
- 中断函数
- **************************************************************************/
- void int0(void) interrupt 0
- {
- dispcount++; //每一次中断,计数加一
- }
- /*************************************************************************
- 主函数
- **************************************************************************/
- void main(void)
- {
- IT0=1; //INT0下降沿中断
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
trycry.rar
(70.62 KB, 下载次数: 49)
|