MSP430驱动DDS模块AD9851
扫描二维码
随时随地手机看文章
#include"msp430x14x.h"
#definead9581_w_clkP2DIR|=BIT0//写时钟信号于P2.0口
#definead9581_w_clk_HP2OUT|=BIT0//P2.0输出高电平
#definead9581_w_clk_LP2OUT&=~BIT0//P2.0输出低电平
#definead9851_fq_upP2DIR|=BIT1//写频率值于P2.1口
#definead9851_fq_up_HP2OUT|=BIT1//P2.1输出高电平
#definead9851_fq_up_LP2OUT&=~BIT1//P2.1输出低电平
#definead9851_restP2DIR|=BIT2//写复位信号P2.1口
#definead9851_rest_HP2OUT|=BIT2//P2.2输出高电平
#definead9851_rest_LP2OUT&=~BIT2//P2.2输出低电平
#definead9851_bit_dataP4DIR|=BIT7//写数据于P4.7口
#definead9851_bit_data_HP4OUT|=BIT7//P4.7输出高电平
#definead9851_bit_data_LP4OUT&=~BIT7//P4.7输出低电平
//***************************************************//
//ad9851复位(并口模式)//
//---------------------------------------------------//
voidad9851_reset()
{
ad9581_w_clk;
ad9581_w_clk_L;
ad9851_fq_up;
ad9851_fq_up_L;
//rest信号
ad9851_rest;
ad9851_rest_L;
ad9851_bit_data_H;
ad9851_bit_data_L;
}
//***************************************************//
//ad9851复位(并口模式)//
//---------------------------------------------------//
voidad9851_reset_serial()
{
ad9581_w_clk;
ad9581_w_clk_L;
ad9851_fq_up;
ad9851_fq_up_L;
//rest信号
ad9851_rest;
ad9851_rest_L;
ad9851_bit_data_H;
ad9851_bit_data_L;
//w_clk信号
//ad9581_w_clk;
ad9581_w_clk_L;
ad9581_w_clk_H;
ad9581_w_clk_L;
//fq_up信号
//ad9851_fq_up;
ad9851_fq_up_L;
ad9851_fq_up_H;
ad9851_fq_up_L;
}
//***************************************************//
//向ad9851中写命令与数据(并口)//
//---------------------------------------------------//
voidad9851_wr_parrel(unsignedcharw0,doublefrequence)
{
unsignedcharw;
longinty;
doublex;
//计算频率的HEX值
x=4294967295/180;//适合180M晶振/180为最终时钟频率(或30M六倍频)
//如果时钟频率不为180MHZ,修改该处的频率值,单位MHz!!!
frequence=frequence/1000000;
frequence=frequence*x;
y=frequence;
P4DIR|=0xFF;
//写w0数据
w=w0;
P4OUT|=w;//w0
ad9581_w_clk_H;
ad9581_w_clk_L;
//写w1数据
w=(y>>24);
P4OUT|=w;//w1
ad9581_w_clk_H;
ad9581_w_clk_L;
//写w2数据
w=(y>>16);
P4OUT|=w;//w2
ad9581_w_clk_H;
ad9581_w_clk_L;
//写w3数据
w=(y>>8);
P4OUT|=w;//w3
ad9581_w_clk_H;
ad9581_w_clk_L;
//写w4数据
w=(y>>=0);
P4OUT|=w;//w4
ad9581_w_clk_H;
ad9581_w_clk_L;
//移入始能
ad9581_w_clk_H;
ad9581_w_clk_L;
}
//***************************************************//
//向ad9851中写命令与数据(串口)//
//---------------------------------------------------//
voidad9851_wr_serial(unsignedcharw0,doublefrequence)
{
unsignedchari,w;
longinty;
doublex;
ad9851_bit_data;
//计算频率的HEX值
x=4294967295/180;//适合180M晶振/180为最终时钟频率(或30M六倍频)
//如果时钟频率不为180MHZ,修改该处的频率值,单位MHz!!!
frequence=frequence/1000000;
frequence=frequence*x;
y=frequence;
//写w4数据
w=(y>>=0);
for(i=0;i<8;i++)
{
ad9851_bit_data_H|((w>>i)&0x01);
ad9581_w_clk_H;
ad9581_w_clk_L;
}
//写w3数据
w=(y>>8);
for(i=0;i<8;i++)
{
ad9851_bit_data_H|((w>>i)&0x01);
ad9581_w_clk_H;
ad9581_w_clk_L;
}
//写w2数据
w=(y>>16);
for(i=0;i<8;i++)
{
ad9851_bit_data_H|((w>>i)&0x01);
ad9581_w_clk_H;
ad9581_w_clk_L;
}
//写w1数据
w=(y>>24);
for(i=0;i<8;i++)
{
ad9851_bit_data_H|((w>>i)&0x01);
ad9581_w_clk_H;
ad9581_w_clk_L;
}
//写w0数据
w=w0;
for(i=0;i<8;i++)
{
ad9851_bit_data_H|((w>>i)&0x01);
ad9581_w_clk_H;
ad9581_w_clk_L;
}
//移入始能
ad9851_fq_up_H;
ad9851_fq_up_L;
}
intmain(void)
{
//Stopwatchdogtimertopreventtimeoutreset
WDTCTL=WDTPW+WDTHOLD;
//---------------------------------------------------//
//并行写1000Hz程序
ad9851_reset();
ad9851_wr_serial(0x01,1000);
//0X01为开六备频
//ad9851_wr_parrel(0x00,1000);
//0X00为不开六备频
//---------------------------------------------------//
//---------------------------------------------------//
//串行写1000Hz程序
//ad9851_reset_serial();
//ad9851_wr_serial(0x01,1000);
//0X01为开六备频
//ad9851_wr_serial(0x00,1000);
//0X00为不开六备频
//---------------------------------------------------//
while(1)
{
}
return0;
}