常用函数波形发生器的设计Word文档下载推荐.docx
《常用函数波形发生器的设计Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《常用函数波形发生器的设计Word文档下载推荐.docx(20页珍藏版)》请在冰豆网上搜索。
ADDB、ADDC分别接K0,K1,K2开关,波动开关状态为000或001,分别选择0通道或1信号
输出到计算机屏幕上显示。
四、设计思路
微机利用软件编程,通过DAC0832数模转换输出端口OUT2输出0~5V的连续模拟电
压(波形),然后将此模拟电压作为ADC0809模数转换的一路输入信号接到IN0端口,地址
信号ADDA、ADDB、ADDC分别接K0,K1,K2开关,选择0通道(000),输出的八位数字信号可
以连接到8255的PA口,控制信号接PB口和PC口,通过采集程序实时读取采集到得数据,
并输入到微机,最后在计算机屏幕上以图形方式显示出来。
注意事项:
D/AC0832和A/DC0809的采样频率应小于640KHz。
五、操作步骤
1.提交设计方案
包括:
控制功能实现方案,编程语言,硬件设计方案及硬件连线图,硬件支持环境
和软件支持的环境要求。
2.方案审核
系统设计方案经过指导老师审核后,方可以实施操作。
3.硬件系统实现
按照硬件设计方案及硬件连线图连线,经过指导老师认可后,加、电并观察是否正
确。
如果发现异常,立刻关掉电源,查明原因,解决问题后,再加电观察。
4.按照功能要求编程,运行,调试
六、撰写课程设计报告及其内容
1.应用系统设计方案
2.系统测试结果
3.课课程设计中遇到的问题及解决办法
4.写出体会与建议
七、课程设计实验环境:
1.硬件配置:
微机一台(Pentium4)
微机接口技术实验箱一个
ISA–PCI转接卡一块
连接电缆一条
万用表一块
微机接口技术实验讲义一本
导线、剥线钳等
2.软件环境:
WindowsXP平台
VisualC++6.0编译器
八、应用系统设计方案
1.主程序
#include"
stdafx.h"
FuncitonProducer.h"
FuncitonProducerDlg.h"
PCI9052Dll.h"
#include<
cmath>
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
#definePI3.141592654
intstyle=-1;
//选择的波形类型
intx=70,y=480,a=0;
intrange=1;
intstb=0;
doublerate=0.5;
doublefrequence=1;
intre=1;
inttimeq=20;
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
publicCDialog
{
public:
CAboutDlg();
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);
//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
:
CAboutDlg():
CDialog(CAboutDlg:
IDD)
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
voidCAboutDlg:
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//Nomessagehandlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//CFuncitonProducerDlgdialog
CFuncitonProducerDlg:
CFuncitonProducerDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CFuncitonProducerDlg:
IDD,pParent)
//{{AFX_DATA_INIT(CFuncitonProducerDlg)
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->
LoadIcon(IDR_MAINFRAME);
voidCFuncitonProducerDlg:
//{{AFX_DATA_MAP(CFuncitonProducerDlg)
DDX_Control(pDX,IDC_COMBO1,m_style);
DDX_Control(pDX,IDC_EDIT_RATE,m_rate);
DDX_Control(pDX,IDC_EDIT_RANGE,m_range);
DDX_Control(pDX,IDC_EDIT_FREQUENCE,m_frequence);
BEGIN_MESSAGE_MAP(CFuncitonProducerDlg,CDialog)
//{{AFX_MSG_MAP(CFuncitonProducerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_START,OnStart)
ON_BN_CLICKED(IDC_BUTTON_STOP,OnStop)
ON_WM_TIMER()
//CFuncitonProducerDlgmessagehandlers
BOOLCFuncitonProducerDlg:
OnInitDialog()
OnInitDialog();
//Add"
About..."
menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&
0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<
0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
{
CStringstrAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!
strAboutMenu.IsEmpty())
{
pSysMenu->
AppendMenu(MF_SEPARATOR);
AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'
smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);
//Setbigicon
SetIcon(m_hIcon,FALSE);
//Setsmallicon
//TODO:
Addextrainitializationhere
m_range.SetWindowText("
1"
);
m_rate.SetWindowText("
0.5"
m_frequence.SetWindowText("
m_style.SetWindowText("
请选择波形"
returnTRUE;
//returnTRUEunlessyousetthefocustoacontrol
OnSysCommand(UINTnID,LPARAMlParam)
if((nID&
0xFFF0)==IDM_ABOUTBOX)
CAboutDlgdlgAbout;
dlgAbout.DoModal();
else
CDialog:
OnSysCommand(nID,lParam);
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
OnPaint()
if(IsIconic())
CPaintDCdc(this);
//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
//Centericoninclientrectangle
intcxIcon=GetSystemMetrics(SM_CXICON);
intcyIcon=GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&
rect);
intx=(rect.Width()-cxIcon+1)/2;
inty=(rect.Height()-cyIcon+1)/2;
//Drawtheicon
dc.DrawIcon(x,y,m_hIcon);
OnPaint();
//画x轴
CClientDCinitdc(this);
initdc.MoveTo(70,480);
initdc.LineTo(70,310);
initdc.LineTo(65,315);
initdc.MoveTo(70,310);
initdc.LineTo(75,315);
//画y轴
initdc.LineTo(750,480);
initdc.LineTo(745,475);
initdc.MoveTo(750,480);
initdc.LineTo(745,485);
//标注y轴
for(inti=1;
i<
=5;
i++)
initdc.MoveTo(70,480-30*i);
initdc.LineTo(75,480-30*i);
//标注x轴
for(i=1;
=10;
initdc.MoveTo(70+60*i,480);
initdc.LineTo(70+60*i,475);
//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags
//theminimizedwindow.
HCURSORCFuncitonProducerDlg:
OnQueryDragIcon()
return(HCURSOR)m_hIcon;
OnStart()
Addyourcontrolnotificationhandlercodehere
Invalidate();
OnPaint();
charstr[25];
style=m_style.GetCurSel();
m_range.GetWindowText(str,25);
if(atoi(str)>
3||atoi(str)<
1)
MessageBox("
请重新输入幅度值!
范围1~3"
"
错误"
MB_ICONEXCLAMATION);
m_range.SetSel(0,-1);
m_range.ReplaceSel("
"
m_range.SetWindowText("
range=atoi(str);
if(style==0)
m_rate.GetWindowText(str,25);
if(atof(str)>
=1||atof(str)<
=0)
MessageBox("
请重新输入占空比!
范围0,1"
m_rate.SetSel(0,-1);
m_rate.ReplaceSel("
m_rate.SetWindowText("
else
rate=atof(str);
m_frequence.GetWindowText(str,25);
if(atof(str)>
2||atof(str)<
0.5)
请重新输入频率!
范围0.5~2"
m_frequence.SetSel(0,-1);
m_frequence.ReplaceSel("
m_frequence.SetWindowText("
frequence=atof(str);
//if(!
strcmp(str,"
方波"
))style=0;
if(-1==style)
请选择波形!
elseif(0==style)
SetTimer(1,timeq,0);
x=70,y=480,a=0;
elseif(1==style)
SetTimer(2,timeq,0);
elseif(2==style)
SetTimer(3,timeq,0);
x=70,y=480;
SetTimer(4,timeq,0);
x=70;
OnStop()
if(0==style)
KillTimer
(1);
KillTimer
(2);
KillTimer(3);
KillTimer(4);
OnTimer(UINTnIDEvent)
Addyourmessagehandlercodehereand/orcalldefault
intt;
switch(nIDEvent)
case1:
CClientDCidc(this);
idc.MoveTo(x,y);
t=a%(int)(120/frequence);
if(t==0||t==rate*120/frequence)
{
if(y==480)
y=480-range*30;
else
y=480;
idc.LineTo(x,y);
}
{
CPointpp;
pp.x=x;
//pp.y=y;
pp.y=DA_AD((unsignedchar)(y-390))+390;
idc.SetPixel(pp,RGB(0,255,0));
}
x++;
a++;
};
break;
case2:
if(a%60==0)
y=480;
else
CPointpp;
pp.x=x;
pp.y=DA_AD((unsignedchar)(y-390))+390;
idc.SetPixel(pp,RGB(0,255,0));
x+=(int)(2.0/frequence);
y-=range;
a+=2;
case3:
CPointpp;
pp.x=x;
//pp.y=y;
pp.y=DA_AD((unsignedchar)(y-300))+300;
idc.SetPixel(pp,RGB(0,255,0));
y=(int)(-sin((x-10)*PI/30.0*frequence)*30*range+420);
x+=1;
case4:
pp.y=-DA_AD(25)+500;
OnTimer(nIDEvent);
unsignedcharCFuncitonProducerDlg:
DA_AD(unsignedchartochange)
staticunsignedshortBASE_ADDR,P_ADDR,DA_ADDR;
staticunsignedchardata,Idata;
OpenDevice();
GetIoBase(&
BASE_ADDR);
P_ADDR=BASE_ADDR+0x08;
//8255基地址,0b000010**
DA_ADDR=BASE_ADDR;
//0832基地址,0b000001**
//8255初始化
data=0x8B;
//都是方式0,A口输出,B、C口输入
OutByte(P_ADDR+3,