-
实验内容及要求
波形发生器广泛地应用于电子和通信等领域,是应用最广泛的电子仪器之一,本设计用51单片机以及DAC0832实现基本波形的输出,参考电路如下:
设计要求:
- 可以产生方波、三角波、正弦波、锯齿波等波形,用仿真的示波器查看。
- 用4个按键分别控制输出相应波形。
- 利用C51设计程序完成以上功能,上述电路仅供参考,可自行创新设计。
- 在keil中利用C51进行程序设计,利用ptoteus设计电路并进行仿真。
-
涉及的主要知识点
- 51单片机的总线。
- DAC0832的工作原理。
- Keil及proteus软件的使用。
-
提示及预备知识
- 教材189页例8.3提供了锯齿波的程序,可修改相应波形显示数据变成相应波形。
- 循环扫描当前按键,若识别到相应按键按下,调用相应波形的显示函数。
代码如下:
#include<reg51.h>
#include<math.h>
sbit P3_0=P3^0;
sbit P3_1=P3^1;
sbit P3_2=P3^2;
sbit P3_3=P3^3;
void delay(unsigned int time)
{
unsigned char j;
for(;time>0;time--)
for(j=0;j<125;j++);
}
unsigned char code sin_tab[] = //正弦波输出表
{
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,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,
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,0xDF,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,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,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,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,0x55,0x57,0x5A,0x5D,0x60,0x63,0x66,0x69,0x6C,0x6F,0x72,0x76,0x79,0x7C,0x7E
};
void main(void)
{
while(1)
{
int i=0;
if(P3_0==0&&P3_1==1&&P3_2==1&&P3_3==1) //输出方波
{
P2=0;
delay(50);
P2=255;
delay(50);
}
if(P3_1==0&&P3_0==1&&P3_2==1&&P3_3==1) //输出三角波
{
for(i=0;i<255;i++)
{
P2=i;
}
for(i=255;i>0;i--)
{
P2=i;
}
}
if(P3_2==0&&P3_0==1&&P3_1==1&&P3_3==1) //输出锯齿波
{
P2=0;
for(i=0;i<255;i++)
{
P2=i;
}
}
if(P3_3==0&&P3_0==1&&P3_1==1&&P3_2==1) //输出正弦波
{
for(i=0;i<255;i++)
{
P2=sin_tab[i];
}
}
}
}
运行结果:
1.P30输出方波
2.P31输出三角波
3.P32输出锯齿波
4.P33输出正弦波
文章来源:https://www.toymoban.com/news/detail-522715.html
文章来源地址https://www.toymoban.com/news/detail-522715.html
到了这里,关于单片机实验——简易波形发生器设计的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!