找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

DDS信号发生器

[复制链接]
admin 发表于 2012-9-2 14:07:51 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
/*
"单片机控制板+AD9850模块"源程序
*/
//在如下的变量定义当中有些可能没有使用;
//您可酌情处理!
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
long uint Frequency_Out;
double Con_Word_1 = 0x00;
double Con_Word_2 = 0x00;
long uint ConTrol_Word = 0x00;//根据设置的频率换算成将要送入AD9850
中的整数量;
uchar dingshiqilideshijianbianliang = 0x00;
uchar keyzhi = 0x00;
uchar AnJianCiShuBiangLiang = 0x00;
long uint SheZhiZhongYaoXianShiDeShuJu = 0x00;
long uint Out_Signal_Max = 3000000;
uchar lianjiabiaozhi = 0x00;lianjianbiaozhi = 0x00;
sbit Light = P1^0; //程序状态指示灯,它与单片机对9850控制无关,只是
调程序的时候使用!
sbit reset = P1^2; //ad9850 reset
sbit fqud = P1^3; //ad9850 fqud;
sbit w_clk = P1^4; // ad9850 w_clk;

delay(long int n)
{
while(n!=0)
{
n--;
}
}
Send_Control_Word(long uint ConTrol_Word)
{
long uint ConTrol_Word_Temporary ;
uchar data_word ;
w_clk = 0x00; //根据时序图
fqud = 0x00; //根据时序图

data_word = 0x00; //相位、掉电等相关控制字//AD9850倍频控制字
P2 = data_word;
delay(300);
w_clk=1;
delay(300);
w_clk=0;
ConTrol_Word_Temporary = ConTrol_Word;
ConTrol_Word = ConTrol_Word >> 24;
data_word = ConTrol_Word % 256;//取出W1,频率控制字中的最高字节

P2 = data_word;
delay(300);
w_clk=1;
delay(300);
w_clk=0;
ConTrol_Word = ConTrol_Word_Temporary;

ConTrol_Word = ConTrol_Word >> 16;
data_word = ConTrol_Word % 256;//取出W2,频率控制字中的次高字节

P2 = data_word;
delay(300);
w_clk=1;
delay(300);
w_clk=0;
ConTrol_Word = ConTrol_Word_Temporary;

ConTrol_Word = ConTrol_Word >> 8;
data_word = ConTrol_Word % 256;//取出W3,频率控制字中的第三字节

P2 = data_word;
delay(300);
w_clk=1;
delay(300);
w_clk=0;
ConTrol_Word = ConTrol_Word_Temporary;
data_word = ConTrol_Word % 256;//取出W4,频率控制字中的最后一个
字节;
P2 = data_word;
delay(300);
w_clk=1;
delay(300);
w_clk=0; //根据时序图
fqud=1; //根据时序图
}
Calculate_Control_Word(long uint Frequency_Out)
{

Con_Word_1 = Frequency_Out * 85;
Con_Word_2 = Frequency_Out *0.88423027547;//50MHz计算方法

Con_Word_2 = Con_Word_2 + 0.5;
Con_Word_1 = Con_Word_1 + Con_Word_2;
//根据设定的频率以浮点形式计算控制字
ConTrol_Word = Con_Word_1 / 1;//将控制字换算成整数形式

ConTrol_Word=0x00,0x05,0x76,0x1A;
}


main()
{

reset = 1; //复位AD9850;
delay(60000);
reset = 0; //取消复位使AD9850进入正常工作状态;
Frequency_Out = 10000;//设定频率的输出值,对于一个完整的控制系统
要通过按键和显示电路结合实现;
//"10000"代表频率为
10000Hz;
while(1)
{
Calculate_Control_Word(Frequency_Out);delay(10000);

Send_Control_Word(ConTrol_Word);

while(1)
{
Light =~Light;

delay(10000);
}

}
}
一线工人帮忙给看看吧 有什么错误 谢谢了
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-25 03:01 , Processed in 0.049524 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表