搞了好几天了,就是没有成功,现在信号能顺利的发给AD9833,但是输出的结果是一个随机错误的信号,单片机复位后不一样,非我想要的,甚至会出现AM调制波。
AD9833:DDS 芯片 MCU:AT89S51 ,开发环境:KeilC51
硬件连接:DDS CLK :P04 ,DDS Data :P37 DDS EN:P05
寻求各位网友指点、斧正。
程序如下:
Config.H文件:
****************************************
#include ".includeat89X52.H"
//typedef unsigned char uint8;
//extern void hardware_test();
//sbit DDSCS = 0x80; // P0_0
//sbit _595CS = 0x81; // P0_1
sbit DDSCLK = 0x84; // P0_4
sbit DDSEN = 0x85; // P0_5
sbit DDSData = 0xB7; // P3_7
extern void DDSIni();
extern void LDelay(unsigned char DelayNum);
extern void SDelay(unsigned char DelayNum);
extern void AD9833_reset();
extern void AD9833_writedata(unsigned int DDSdata);
extern void Load_wave(unsigned int Contr_Reg_data,unsigned int Fre_MSBdata,unsigned int Fre_LSBdata,unsigned int Phs_data);
AD9833.c文件:
******************************
//C Files
#include "config.h"
void DDSIni()
{
/*
P1_2=0;
DDSCS=0; // DDSCS able
_595CS=1; //595CS disable
*/
DDSEN=1; //DDSEN disable
DDSCLK=1; //Clock high
DDSData=0;
AD9833_reset();
}
void LDelay(unsigned char DelayNum)
{
unsigned char Delay1p6mS=0XFF;
while(DelayNum--)
{
while(Delay1p6mS--);
}
}
void SDelay(unsigned char DelayNum)
{
while(DelayNum--);
}
/////////////////////////////////////
/*函数描述:
/*写入参数:
/*返回参数:
/*作者:
/*日期:
*////////////////////////////////////
void AD9833_reset()
{
//add code here
AD9833_writedata(0x2100); //准备清空频率寄存器0
AD9833_writedata(0x4000); //Filled with 0
AD9833_writedata(0x4000); //Filled with 0
AD9833_writedata(0x2900); //Prepare for clear Fre1
AD9833_writedata(0x8000); //Filled with 0
AD9833_writedata(0x8000); //Filled with 0
AD9833_writedata(0xD000); //clear PHS 0
AD9833_writedata(0xF000); //clear PHS 1
}
void AD9833_writedata(unsigned int DDSdata)
{
unsigned char data_num=0;
unsigned int DDSdata_temp;
DDSdata_temp=DDSdata;
DDSCLK=1;
SDelay(80);
DDSEN=0; //DDS able
SDelay(80);
for(data_num=0;data_num<16;data_num++)
{
if(DDSdata_temp & 0X8000 )
{
DDSData=1;
}
else
{
DDSData=0;
}
SDelay(50);
DDSCLK=0;
SDelay(100);
/*
DDSData=0;
SDelay(100);
*/
DDSCLK=1;
DDSdata_temp=DDSdata_temp<<1;
if(data_num < 15)
{
SDelay(1000);
}
}
DDSEN=1;
}
void Load_wave(unsigned int Contr_Reg_data,unsigned int Fre_MSBdata,unsigned int Fre_LSBdata,unsigned int Phs_data)
{
//add
unsigned int Fre_MSBdata_temp=Fre_MSBdata;
unsigned int Fre_LSBdata_temp=Fre_LSBdata;
unsigned int Contr_Reg_data_temp=Contr_Reg_data;
unsigned int Phs_data_temp=Phs_data;
AD9833_writedata(Contr_Reg_data_temp);
AD9833_writedata(Fre_LSBdata_temp);
AD9833_writedata(Fre_MSBdata_temp);
AD9833_writedata(Phs_data);
}
main.c 文件
********************************************
//main files
#include "config.h"
main()
{
//add code here
//hardware_test();
LDelay(0XFF);
LDelay(0XFF);
DDSIni();
Load_wave(0x2100,0x400F,0x4FFF,0xD000);
while(1)
{
;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
找到原因如下:上述代码中有关复位控制寄存器的命令要单写,而不能与修改控制寄存器的命令一起写!既:0X2100要先写0X0100,然后0X2000两个步骤。后续会贴出图片以及最后的源代码。
一周热门 更多>