//-----------------------函数声明,变量定义--------------------------------------------------------
#include <reg52.h>
#include <intrins.h>
#include <ABSACC.H>
//-----------------------定义管脚--------------------------------------------------------
#define data_OUT P1
#define uchar unsigned char
sbit FQ_UD=P2^7; //AD9850信号更新申请
sbit W_CLK=P2^6; //写控制字时钟
sbit WD=P3^3;
uchar CON_word[5];
//--------------------------------------------------------------------------------------------------
// 函数名称: init_dds()
// 函数功能: DDS初始化
//--------------------------------------------------------------------------------------------------
void init_dds(void)
{
W_CLK=0;
FQ_UD=0;
W_CLK=1;
W_CLK=0;
FQ_UD=1;
FQ_UD=0;
}
//--------------------------------------------------------------------------------------------------
// 函数名称: WRITE_AD9850
// 函数功能: 将控制字写入AD9850
//--------------------------------------------------------------------------------------------------
void Freq_Adjust(unsigned long value_Freq)
{
uchar i;
unsigned long f;
uchar L4,L3,L2,L1,L0;
FQ_UD=0;
f=value_Freq*34.359738368;
L0=0x00;
L4= f&0x000000ff;
L3=(f>>8)&0x000000ff;
L2=(f>>16)&0x000000ff;
L1=(f>>24)&0x000000ff;
CON_word[0]=L0;
CON_word[4]=L4;
CON_word[3]=L3;
CON_word[2]=L2;
CON_word[1]=L1;
FQ_UD=0;
W_CLK=0;
for(i=0;i<5;i++)
{
data_OUT=CON_word[i]; //送控制字
W_CLK=0;
W_CLK=1; //上升延
}
W_CLK=0;
FQ_UD=1;
FQ_UD=0;
}
//--------------------------------------------------------------------------------------------------
// 函数名称:main
// 用户主函数
// 函数功能:主函数
//--------------------------------------------------------------------------------------------------
void main()
{
init_dds();
FQ_UD=0;
Freq_Adjust(15);//输出频率为15Hz
TMOD=0x00;
TH0=0xC1;TL0=0x10;
TR0=1;
while(1)
{
do{}while(!TF0);
WD=!WD;
}
while(1);
}