51单片机制作的波形发生器

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

51单片机制作的波形发生器

相信很多朋友都可能接触到一个波型发生器的制作,可能刚刚入门,做的东西也不会说是很复杂。可能就一

个矩形波,或者是三角波。但是网上的很多资料是忽悠

人的,就此,我也提供一个比较完整的波型发生器 C51 原代:

该系统的软件比较典型:包括键盘的应用,显示的

应用和 DA 转换器的应用。本设计中,输出的波形有三种:正弦波,方波,三角波。

方波的输出最为简单,只要按照设定的周期值将输

出的电压改变即可。

三角波的输出也比较简单,单片机的输出只要完成

数字量递增和递减交替进行即可。、

正弦波的输出最麻烦,如果在软件中计算出输出的

各点电压值,将会浪费很多的 CPU 时间,以至于无法满足频率的要求。通常最简单的方法是通过手动的方法计

算出输出各点的电压值,然后在编写程序时以数组的方

式给出。当需要时,只要按照顺序进行输出即可。这种

方法比运算法速度快且曲线的形状修改灵活。在本设计

中将 360 度分为 256 个点,则每两个点之间的间隔为1.4 度,然后计算出每个点电压对应的数字量即可。只

要反复输出这组数据到 DAC0832, 就可以在系统输出端得到想要的正弦波。

具体程序如下:

#include ;

#define uchar unsigned char

#define uint unsigned int

#define DAdata P0

uchar code Sinetab[256]=

{

0x80,0x82,0x84,0x86,0x88,0x8a,0x8c,0x8e,

0x90,0x92,0x94,0x96,0x98,0x9a,0x9c,0x9e,

0xa0,0xa2,0xa4,0xa6,0xa8,0xaa,0xab,0xad,

0xaf,0xb1,0xb2,0xb4,0xb6,0xb7,0xb9,0xba,

0xbc,0xbd,0xbf,0xc0,0xc1,0xc3,0xc4,0xc5,

0xc6,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,

0xce,0xcf,0xd0,0xd1,0xd1,0xd2,0xd2,0xd3,

0xd3,0xd3,0xd2,0xd2,0xd1,0xd1,0xd0,0xcf,

0xce,0xce,0xcd,0xcc,0xcb,0xca,0xc9,0xc8,

0xc6,0xc5,0xc4,0xc3,0xc1,0xc0,0xbf,0xbd,

0xbc,0xba,0xb9,0xb7,0xb6,0xb4,0xb2,0xb1,

0xaf,0xad,0xab,0xaa,0xa8,0xa6,0xa4,0xa2,

0xa0,0x9e,0x9c,0x9a,0x98,0x96,0x94,0x92,

0x90,0x8e,0x8c,0x8a,0x88,0x86,0x84,0x82, 0x80,0x7d,0x7b,0x79,0x77,0x75,0x73,0x71, 0x6f,0x6d,0x6b,0x69,0x67,0x65,0x63,0x61, 0x5f,0x5d,0x5b,0x59,0x57,0x55,0x54,0x52, 0x50,0x4e,0x4d,0x4b,0x49,0x48,0x46,0x45, 0x43,0x42,0x40,0x3f,0x3e,0x3c,0x3b,0x3a, 0x39,0x37,0x36,0x35,0x34,0x33,0x32,0x31, 0x31,0x30,0x2f,0x2e,0x2e,0x2d,0x2d,0x2c, 0x2c,0x2b,0x2b,0x2b,0x2b,0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,0x2a,0x2b,0x2b,0x2b,0x2b, 0x2c,0x2c,0x2d,0x2d,0x2e,0x2e,0x2f,0x30, 0x31,0x31,0x32,0x33,0x34,0x35,0x36,0x37, 0x39,0x3a,0x3b,0x3c,0x3e,0x3f,0x40,0x42, 0x43,0x45,0x46,0x48,0x49,0x4b,0x4d,0x4e, 0x50,0x52,0x54,0x55,0x57,0x59,0x5b,0x5d, 0x5f,0x61,0x63,0x65,0x67,0x69,0x6b,0x6d, 0x6f,0x71,0x73,0x75,0x77,0x79,0x7b,0x7d, };

uchar code Triangletab[58]=

{

0x1a,0x21,0x28,0x2f,0x36,0x3d,0x44,0x4b, 0x52,0x59,0x60,0x67,0x6e,0x75,0x7c,0x83,

0x8a,0x91,0x98,0x9f,0xa6,0xad,0xb4,0xbb,

0xc2,0xc9,0xd0,0xd7,0xde,0xe5,

0xde,0xd7,0xd0,0xc9,0xc2,0xbb,0xb4,0xad,

0xa6,0x9f,0x98,0x91,0x8a,0x83,0x7c,0x75,

0x6e,0x67,0x60,0x59,0x52,0x4b,0x44,0x3d,

0x36,0x2f,0x28,0x21,

};

uchar code Squaretab[2]={0x56,0xaa};

uchar code disp1[]=

{

"Sine Wave "

"Triangle Wale "

"Square Wave "

};

uchar idata disp2[16]={"Frequency:

Hz"};

uchar code Coef[3]={10,100,200};

uchar idata WaveFre[3]={1,1,1};

uchar code WaveTH[]=

{

0xfc,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xfc,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

相关文档
最新文档