1、基于单片机的简易函数信号发生器创新性实验研究报告实验项目名称简易函数信号发生器 一、实验摘要 用AT89C51单片机采用程序设计方法构成的波形发生器,可产生方波、三角波、正弦波,再通过DA转换器DAC0832将数字信号转换成模拟信号,并通过LM324集成运放把信号放大,通过示波器将波形显示在屏幕上。波形的周期可用程序改变,此设计具有线路简单、结构紧凑、性能优越等特点。通过仿真测试,其性能指标达到了设计要求。并进行实际焊接电路板,进行波形测试,均达到了实验目的。二、实验目的1、进行硬件电路设计。2、编写程序,并进行程序测试。3、利用单片机采用软件设计方法产生三种波形。4、焊接电路,将程序下载到单
2、片机,并用示波器对输出程序进行测试。三、实验场地及仪器、设备和材料:实验场地:电子技术实验室。仪器、设备和材料:双通道数字示波器、AT89C52单片机、DAC0832、LM324、电脑、杜邦线、洞洞板、电烙铁等。四、实验内容1、实验原理数字信号可以通过数/模转换器转换成模拟信号,因此可通过产生数字信号再转换成模拟信号的方法来获得所需要的波形。89C51单片机本身就是一个完整的微型计算机,具有组成微型计算机的各部分部件:中央处理器CPU、随机存取存储器RAM、只读存储器ROM、I/O接口电路、定时器/计数器以及串行通讯接口等,只要将89C51再配置键盘及其接口、显示器及其接口、数模转换及波形输出
3、、指示灯及其接口等四部分,即可构成所需的波形发生器,其信号发生器构成原理框图如下图所示。滤波放大电路数模转换电路单片机 89C51是整个波形发生器的核心部分,通过程序的编写和执行,产生各种各样的信号,当数字信号电路到达转换电路,将其转换成模拟信号也就是所需要的输出波形。并经过滤波放大电路将波形输出出来。2、实验内容 1、运用keil软件对程序进行编写,运行程序,并进行程序修改。 2、运用protues软件进行硬件电路仿真设计。 3、将程序下载到仿真单片机中,并观测输出波形。 4、对程序进行修改,再次运行仿真软件,直到输出理想的波形。 5、仿照仿真软件进行硬件电路的焊接。 6、将程序下载到单片机
4、,并用示波器测试输出波形。 7、对程序进行修改,直到输出满意的波形为止。3、实验步骤1、首先打开keil软件. 2、运用keil软件对程序进行编写,程序见附件。3、打开protues软件.4、运用protues软件对硬件电路进行设计。9C51单片机是该信号发生器的核心,具有2个定时器,32个并行I/O口,1个串行I/O口,5个中断源。由于本设计功能简单,数据处理容易,数据存储空间也足够,因为我们采用了片选法选择芯片,进行芯片的选择和地址的译码。在单片机最小最小系统中,单片机从P1口接收来自键盘的信号,并通过P0口输出控制信号,通过DA转换芯片最终由示波器显示输出波形。单片机引脚分配如下:?XT
5、AL1,XTAL2:外接晶振,产生时钟信号。?RST:复位电路;?P2口:8位数字信号输出输出,外接DAC0832;?口和口:DAC0832的时钟信号; 单片机模块 单片机输出的是数字信号,因为要得到模拟信号的波形就必须对其进行数模转换。我们采用了DAC0832数模转换器,该芯片具由8位输入锁存器、8位DAC寄存器、8位D/A转换器及转换控制电路四部分构成。由于其输出为电流输出,因为外加运算放大器LM324使之转换为电压输出。最后通过示波器显示输出的波形。 数模转换模块 运放模块 整体硬件电路图五、实验结果与分析1、实验现象、数据记录 仿真波形2、对实验现象、数据及观察结果的分析与讨论:经过观
6、察调试,再观察,再调试,最终输出的波形较为理想。此次试验经过一系列的调试,最终输出的波形为正弦波、方波、三角波。刚开始在给运放接电源时,接的电源不是稳恒直流电源(用示波器测试了一下电源的输出波形,虽然电源上写的是直流稳恒电源,但是发现他的波形掺杂有杂波),所以测出来的波形不是正弦波、方波和三角波。分析原因可能与运放的电源有关,所以在实验室找到了数控稳恒直流电源,经过给运放供电,发现输出了正弦波、方波、三角波。所以给运放供电的电源必须是经滤波后的平稳电源,否则对运放有很大影响。3、关键点: 此次试验关键点是程序的编写,在程序编写的过程中请教了众多的编程高手,最终在大家的帮助下编写出了能输出正弦波
7、、方波、三角波的程序。此次试验另一个关键点是硬件电路的焊接。在硬件电路焊接中首先应根据仿真软件进行焊接,当焊完以后还要对电路进行测试,以防止电路不通。第三个关键点是在给运放供电时的电源一定要是稳恒直流电源,不能掺杂有杂波。六、实验结论基于单片机的信号发生器设计,这个信号发生器的设计中涉及到一个典型的控制过程。通过单片机控制一个模数转换器DAC0832产生所需要的电流,然后使用运算放大器LM324可以将其电流输出线性地转换成电压输出,再将电压经过运算放大器的放大,可以得到足够幅度的信号。通过程序的控制,可以产生一系列有规律的波形。这样一个信号发生装置在控制领域有相当广泛的应用范围。最终做出来的信
8、号发生器满足了题目中的所有要求:产生三种波形。正弦波、三角波、矩形波。 当然还是存在不足的地方,比如不能实现频率的按一个小的步进调整。并且当频率太小时矩形波会有些失真。信号发生器可以生成更多的波形,只需要再加些波形表即可。七、指导老师评语及得分:签名: 年 月 日附件:源程序等。正弦波程序:#include #define uchar unsigned char#define uint unsigned intsbit cs=P37; sbit wr=P36; uchar j;uint ys,a=0;uchar code tosin256= 0x80,0x83,0x86,0x89,0x8d,0
9、x90,0x93,0x96,0x99,0x9c,0x9f,0xa2, 0xa5,0xa8,0xab,0xae,0xb1,0xb4,0xb7,0xba,0xbc,0xbf,0xc2,0xc5, 0xc7,0xca,0xcc,0xcf,0xd1,0xd4,0xd6,0xd8,0xda,0xdd,0xdf,0xe1, 0xe3,0xe5,0xe7,0xe9,0xea,0xec,0xee,0xef,0xf1,0xf2,0xf4,0xf5, 0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfd,0xfe,0xff,0xff, 0xff,0xff,0xff,0xff,0
10、xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd, 0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf2,0xf1, 0xef,0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe1,0xde,0xdd,0xda, 0xd8,0xd6,0xd4,0xd1,0xcf,0xcc,0xca,0xc7,0xc5,0xc2,0xbf,0xbc, 0xba,0xb7,0xb4,0xb1,0xae,0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x99, 0x96,0x93,0x90,0
11、x8d,0x89,0x86,0x83,0x80,0x80,0x7c,0x79,0x76, 0x72,0x6f,0x6c,0x69,0x66,0x63,0x60,0x5d,0x5a,0x57,0x55,0x51, 0x4e,0x4c,0x48,0x45,0x43,0x40,0x3d,0x3a,0x38,0x35,0x33,0x30, 0x2e,0x2b,0x29,0x27,0x25,0x22,0x20,0x1e,0x1c,0x1a,0x18,0x16, 0x15,0x13,0x11,0x10,0x0e,0x0d,0x0b,0x0a,0x09,0x08,0x07,0x06, 0x05,0x04,0
12、x03,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x04,0x05, 0x06,0x07,0x08,0x09,0x0a,0x0b,0x0d,0x0e,0x10,0x11,0x13,0x15, 0x16,0x18,0x1a,0x1c,0x1e,0x20,0x22,0x25,0x27,0x29,0x2b,0x2e, 0x30,0x33,0x35,0x38,0x3a,0x3d,0x40,0x43,0x45,0x48,0x4c,0x4e, 0x51,0
13、x55,0x57,0x5a,0x5d,0x60,0x63,0x66 ,0x69,0x6c,0x6f,0x72, 0x76,0x79,0x7c,0x80 ;/*正弦波码 */ void delay(uint z) /延时子程序 uchar i,j; for(i=z;i0;i-) for(j=110;j0;j-); void delay1(uint y) uint i; for(i=y;i0;i-); void main() cs=1; wr=1; cs=0; wr=0; while(1) /正弦波 P2=tosinj; j+; delay(1); wr=1; cs=1; 方波程序:#includ
14、e #define uchar unsigned char#define uint unsigned intsbit cs=P37; sbit wr=P36; uchar j;uint ys,a=0;uchar code tosin256= 0x80,0x83,0x86,0x89,0x8d,0x90,0x93,0x96,0x99,0x9c,0x9f,0xa2, 0xa5,0xa8,0xab,0xae,0xb1,0xb4,0xb7,0xba,0xbc,0xbf,0xc2,0xc5, 0xc7,0xca,0xcc,0xcf,0xd1,0xd4,0xd6,0xd8,0xda,0xdd,0xdf,0x
15、e1, 0xe3,0xe5,0xe7,0xe9,0xea,0xec,0xee,0xef,0xf1,0xf2,0xf4,0xf5, 0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfd,0xfe,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd, 0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf2,0xf1, 0xef,0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe1,0xde,0x
16、dd,0xda, 0xd8,0xd6,0xd4,0xd1,0xcf,0xcc,0xca,0xc7,0xc5,0xc2,0xbf,0xbc, 0xba,0xb7,0xb4,0xb1,0xae,0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x99, 0x96,0x93,0x90,0x8d,0x89,0x86,0x83,0x80,0x80,0x7c,0x79,0x76, 0x72,0x6f,0x6c,0x69,0x66,0x63,0x60,0x5d,0x5a,0x57,0x55,0x51, 0x4e,0x4c,0x48,0x45,0x43,0x40,0x3d,0x3a,0x38,0x
17、35,0x33,0x30, 0x2e,0x2b,0x29,0x27,0x25,0x22,0x20,0x1e,0x1c,0x1a,0x18,0x16, 0x15,0x13,0x11,0x10,0x0e,0x0d,0x0b,0x0a,0x09,0x08,0x07,0x06, 0x05,0x04,0x03,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x04,0x05, 0x06,0x07,0x08,0x09,0x0a,0x0b,0x0d,0x0e,0x
18、10,0x11,0x13,0x15, 0x16,0x18,0x1a,0x1c,0x1e,0x20,0x22,0x25,0x27,0x29,0x2b,0x2e, 0x30,0x33,0x35,0x38,0x3a,0x3d,0x40,0x43,0x45,0x48,0x4c,0x4e, 0x51,0x55,0x57,0x5a,0x5d,0x60,0x63,0x66 ,0x69,0x6c,0x6f,0x72, 0x76,0x79,0x7c,0x80 ;/*正弦波码 */ void delay(uint z) /延时子程序 uchar i,j; for(i=z;i0;i-) for(j=110;j0;j
19、-); void delay1(uint y) uint i; for(i=y;i0;i-); void main() cs=1; wr=1; cs=0; wr=0; while(1) /方波 P2=0xff; delay(1); P2=0; delay(1); wr=1; cs=1; 三角波程序:#include #define uchar unsigned char#define uint unsigned intsbit cs=P37; sbit wr=P36; uchar j;uint ys,a=0;uchar code tosin256= 0x80,0x83,0x86,0x89,0x
20、8d,0x90,0x93,0x96,0x99,0x9c,0x9f,0xa2, 0xa5,0xa8,0xab,0xae,0xb1,0xb4,0xb7,0xba,0xbc,0xbf,0xc2,0xc5, 0xc7,0xca,0xcc,0xcf,0xd1,0xd4,0xd6,0xd8,0xda,0xdd,0xdf,0xe1, 0xe3,0xe5,0xe7,0xe9,0xea,0xec,0xee,0xef,0xf1,0xf2,0xf4,0xf5, 0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfd,0xfe,0xff,0xff, 0xff,0xff,0xff,0x
21、ff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd, 0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf2,0xf1, 0xef,0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,0xe1,0xde,0xdd,0xda, 0xd8,0xd6,0xd4,0xd1,0xcf,0xcc,0xca,0xc7,0xc5,0xc2,0xbf,0xbc, 0xba,0xb7,0xb4,0xb1,0xae,0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x99, 0x96,0x93,0x
22、90,0x8d,0x89,0x86,0x83,0x80,0x80,0x7c,0x79,0x76, 0x72,0x6f,0x6c,0x69,0x66,0x63,0x60,0x5d,0x5a,0x57,0x55,0x51, 0x4e,0x4c,0x48,0x45,0x43,0x40,0x3d,0x3a,0x38,0x35,0x33,0x30, 0x2e,0x2b,0x29,0x27,0x25,0x22,0x20,0x1e,0x1c,0x1a,0x18,0x16, 0x15,0x13,0x11,0x10,0x0e,0x0d,0x0b,0x0a,0x09,0x08,0x07,0x06, 0x05,0x
23、04,0x03,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x04,0x05, 0x06,0x07,0x08,0x09,0x0a,0x0b,0x0d,0x0e,0x10,0x11,0x13,0x15, 0x16,0x18,0x1a,0x1c,0x1e,0x20,0x22,0x25,0x27,0x29,0x2b,0x2e, 0x30,0x33,0x35,0x38,0x3a,0x3d,0x40,0x43,0x45,0x48,0x4c,0x4e, 0x
24、51,0x55,0x57,0x5a,0x5d,0x60,0x63,0x66 ,0x69,0x6c,0x6f,0x72, 0x76,0x79,0x7c,0x80 ;/*正弦波码 */ void delay(uint z) /延时子程序 uchar i,j; for(i=z;i0;i-) for(j=110;j0;j-); void delay1(uint y) uint i; for(i=y;i0;i-); void main() cs=1; wr=1; cs=0; wr=0; while(1) /三角波 if(a128) P2=a; delay(10); else P2=255-a; delay(10); a+; if(a=255) a=0; wr=1; cs=1;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1