基于CPLD实现的DDS频率计Word文档下载推荐.docx
- 文档编号:21202353
- 上传时间:2023-01-28
- 格式:DOCX
- 页数:15
- 大小:267.59KB
基于CPLD实现的DDS频率计Word文档下载推荐.docx
《基于CPLD实现的DDS频率计Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《基于CPLD实现的DDS频率计Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。
10"
DATAOUTT(23DOWNTO16)<
11"
DATAOUTT(31DOWNTO24)<
ENDCASE;
endif;
ENDPROCESS;
ENDbehav;
(2)32位加法器
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYADDER32BIS
PORT(A:
INSTD_LOGIC_VECTOR(31DOWNTO0);
B:
S:
OUTSTD_LOGIC_VECTOR(31DOWNTO0));
ENDADDER32B;
ARCHITECTUREbehavOFADDER32BIS
S<
=A+B;
(3)32位寄存器
ENTITYREG32BIS
PORT(LOAD:
INSTD_LOGIC;
DIN:
DOUT:
ENDREG32B;
ARCHITECTUREbehavOFREG32BIS
PROCESS(LOAD,DIN)
begin
IFLOAD'
EVENTANDLOAD='
THEN
DOUT<
=DIN;
ENDIF;
ENDPROCESS;
频率计模块代码:
(1)标准频率计数器
ENTITYBZHHIS
PORT(BCLK:
--Fs
BENA:
CLR:
--清零
BZQ:
inOUTSTD_LOGIC_VECTOR(31DOWNTO0));
ENDBZHH;
ARCHITECTUREbehavOFBZHHIS
PROCESS(BCLK,CLR)--标准频率计数开始
BEGIN
IFCLR='
THENBZQ<
=(OTHERS=>
'
0'
);
ELSIFBCLK'
EVENTANDBCLK='
IFBENA='
=BZQ+1;
(2)待测频率计数器
ENTITYTTFFIS
PORT(TCLK:
ENA:
TSQ:
ENDTTFF;
ARCHITECTUREbehavOFTTFFIS
PROCESS(TCLK,CLR,ENA)
THENTSQ<
ELSIFTCLK'
EVENTANDTCLK='
IFENA='
=TSQ+1;
(3)MUX648
ENTITYMUX648IS
PORT(DATAIN1:
DATAIN2:
DATAOUT:
OUTSTD_LOGIC_VECTOR(7DOWNTO0);
SEL:
INSTD_LOGIC_VECTOR(2DOWNTO0));
ENDMUX648;
ARCHITECTUREbehavOFMUX648IS
DATAOUT<
=DATAIN1(7DOWNTO0)WHENSEL="
000"
ELSE--标准频率计低八位输出
DATAIN1(15DOWNTO8)WHENSEL="
001"
ELSE
DATAIN1(23DOWNTO16)WHENSEL="
010"
ELSE
DATAIN1(31DOWNTO24)WHENSEL="
011"
ELSE--标准频率计最高八位输出
DATAIN2(7DOWNTO0)WHENSEL="
100"
ELSE--待测频率计数值低八位输出
DATAIN2(15DOWNTO8)WHENSEL="
101"
DATAIN2(23DOWNTO16)WHENSEL="
110"
DATAIN2(31DOWNTO24)WHENSEL="
111"
ELSE--待测频率计数值最高八位输出
DATAIN2(31DOWNTO24);
单片机程序如下:
主程序
#include<
reg52.h>
intrins.h>
#include"
key.h"
//scankey();
keyexe();
setfre();
testfre();
lcd1602.h"
//display();
voidmain(void)
{
lcd_init();
bena=0;
clr=1;
load_dds=0;
oe=0;
start=1;
lcd_str(0,2,"
dds.and.testfre!
"
while
(1)
{
keyexe();
}
}
键盘程序:
#ifndef__KEY_H__
#define__KEY_H__
#include"
#definedinoutP3;
unsignedcharkeybuffer[8],longtochar[4],recieve[8];
unsignedlongfreword,setdispbuf;
unsignedlongtfrecount,bfrecount;
//Fs、Fx计数值
unsignedlongtfreword;
//-----------pindefineforddsandtestfre------
sbitsel2=P1^2;
sbitsel1=P1^1;
sbitsel0=P1^0;
sbitoe=P2^3;
//-----------pindefineforddsloading----------
sbitload_dds=P2^4;
//-----------pindefinefortestfre--------------
sbitclr=P2^0;
sbitbena=P2^1;
sbitstart=P2^2;
//-----------delayprogramm----------------------
voiddelay(unsignedintn)
while(n--)_nop_();
//-----------formatexchange---------------------
voidkeytofreword(void)
freword=keybuffer[0]*10000000+keybuffer[1]*1000000+keybuffer[2]*100000+keybuffer[3]*10000+keybuffer[4]*1000+keybuffer[5]*100+keybuffer[6]*10+keybuffer[7];
//合成输入频率值
setdispbuf=freword;
freword=(unsignedlong)(freword*214.7493648);
//计算相应的频率字
longtochar[0]=(freword>
>
24)&
0xff;
//频率字最高八位
longtochar[1]=(freword>
16)&
//频率字次高八位
longtochar[2]=(freword>
8)&
//频率字次低八位
longtochar[3]=(freword)&
//频率字最低八位
//-----------selectchannel-----------------------
voidselect(unsignedcharsel)
unsignedchari,j;
j=sel;
sel=sel&
0x07;
i=P1;
i=i&
0xf8;
i=i|sel;
P1=i;
//-----------settingfrequency--------------------
voidsetfre(void)
unsignedchari;
keytofreword();
display(setdispbuf,1);
//显示输入的频率值
--setting.fre!
-"
for(i=0;
i<
4;
i++)
select(i);
P3=longtochar[i];
_nop_();
load_dds=1;
load_dds=0;
--setting.succ!
//----------testfrequency------------------------
voidtestfre(void)
unsignedintj;
--testing.fre---"
clr=0;
_nop_();
//-----clearregister--------清零
bena=1;
//允许频率计开始工作
delay1ms_x(1000);
//门控时间2S
//------countuntilstartequals0------------
j=10000;
while((start==1)&
&
(j--));
//----waitforendoftesttingortimeout---
if(j==0)
lcd_str(0,2,"
--test.fre.err!
else
-test.fre.succ!
oe=1;
//双向口
8;
{
P3=0xff;
//P3作为输入口
recieve[i]=P3;
//读取频率计计数值
bfrecount=0;
tfrecount=0;
bfrecount=(bfrecount<
<
8)+recieve[i];
//合成标准频率计数值
tfrecount=(tfrecount<
8)+recieve[i+4];
//合成待测频率计数值
tfrecount=(unsignedlong)tfrecount/3.5200886+1;
//?
?
display(tfrecount,0);
//-------------------scankeyvalue-------------------------
unsignedcharscankey(void)//键盘扫描
unsignedchari=0xff,k=0xfe,buf;
unsignedcodetable[4]={0xfe,0xfd,0xfb,0xf7};
for(i=0;
{
P1=table[i];
buf=P1;
if(buf!
=table[i])
{
delay(1000);
if(buf==P1)
{
while(buf==P1);
break;
}
}
}
switch(buf)
case0xee:
return1;
case0xed:
return2;
case0xeb:
return3;
case0xe7:
return10;
//4
case0xde:
return4;
//5
case0xdd:
return5;
//6
case0xdb:
return6;
//7
case0xd7:
return11;
//8
case0xbe:
return7;
//9
case0xbd:
return8;
//0
case0xbb:
return9;
//11
case0xb7:
return12;
//12
case0x7e:
return13;
//13
case0x7d:
return0;
//14
case0x7b:
return14;
//15
case0x77:
return15;
//16
default:
return16;
//10
P1=0xff;
//-----------------keyexecution-----------------------
voidkeyexe(void)
unsignedchari,buf;
buf=scankey();
//调键盘扫描,读取键值
switch(buf)
{
case0:
case1:
case2:
case3:
case4:
case5:
case6:
case7:
case8:
case9:
7;
keybuffer[i]=keybuffer[i+1];
keybuffer[7]=buf;
lcd_data1(0,1,'
i'
lcd_data1(1,1,'
n'
lcd_data1(2,1,'
p'
lcd_data1(3,1,'
u'
lcd_data1(4,1,'
t'
lcd_data1(5,1,'
:
lcd_data1(6,1,keybuffer[0]+'
lcd_data1(7,1,keybuffer[1]+'
lcd_data1(8,1,keybuffer[2]+'
lcd_data1(9,1,keybuffer[3]+'
lcd_data1(10,1,keybuffer[4]+'
lcd_data1(11,1,keybuffer[5]+'
lcd_data1(12,1,keybuffer[6]+'
lcd_data1(13,1,keybuffer[7]+'
lcd_data1(14,1,'
H'
lcd_data1(15,1,'
z'
break;
case10:
lcd_cmd(clear);
setfre();
case11:
case12:
{
keybuffer[i]=0;
lcd_data1(i+6,1,keybuffer[i]+'
}
default:
break;
}
#endif
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 CPLD 实现 DDS 频率计