/*
* AD9850.h
*
* Created on: 2013-7-12
* Author: Allen
*/
#ifndef AD9850_H_
#define AD9850_H_
#include
#include "MyType.h"
//----------------------------------------------------------------------------------
//AD9850:W_CLK P2.5
#define AD9850_W_CLK_DIR (P2DIR)
#define AD9850_W_CLK_OUT (P2OUT)
#define AD9850_W_CLK_PIN_NUM (BIT5)
#define AD9850_W_CLK_IO_INIT (Set_Bit(P2DIR,AD9850_W_CLK_PIN_NUM))
#define AD9850_W_CLK_H (Set_Bit(P2OUT,AD9850_W_CLK_PIN_NUM))
#define AD9850_W_CLK_L (Clr_Bit(P2OUT,AD9850_W_CLK_PIN_NUM))
//----------------------------------------------------------------------------------
//AD9850:FQ_UP P2.4
#define AD9850_FQ_UP_DIR (P2DIR)
#define AD9850_FQ_UP_OUT (P2OUT)
#define AD9850_FQ_UP_PIN_NUM (BIT4)
#define AD9850_FQ_UP_IO_INIT (Set_Bit(P2DIR,AD9850_FQ_UP_PIN_NUM))
#define AD9850_FQ_UP_H (Set_Bit(P2OUT,AD9850_FQ_UP_PIN_NUM))
#define AD9850_FQ_UP_L (Clr_Bit(P2OUT,AD9850_FQ_UP_PIN_NUM))
//----------------------------------------------------------------------------------
//AD9850:RESET P2.3
#define AD9850_RESET_DIR (P2DIR)
#define AD9850_RESET_OUT (P2OUT)
#define AD9850_RESET_PIN_NUM (BIT3)
#define AD9850_RESET_IO_INIT (Set_Bit(P2DIR,AD9850_RESET_PIN_NUM))
#define AD9850_RESET_H (Set_Bit(P2OUT,AD9850_RESET_PIN_NUM))
#define AD9850_RESET_L (Clr_Bit(P2OUT,AD9850_RESET_PIN_NUM))
//----------------------------------------------------------------------------------
//AD9850:BIT_DATA P1.7
#define AD9850_BIT_DATA_DIR (P1DIR)
#define AD9850_BIT_DATA_OUT (P1OUT)
#define AD9850_BIT_DATA_PIN_NUM (BIT7)
#define AD9850_BIT_DATA_IO_INIT (Set_Bit(P1DIR,AD9850_BIT_DATA_PIN_NUM))
#define AD9850_BIT_DATA_H (Set_Bit(P1OUT,AD9850_BIT_DATA_PIN_NUM))
#define AD9850_BIT_DATA_L (Clr_Bit(P1OUT,AD9850_BIT_DATA_PIN_NUM))
extern void AD9850_INIT_SERIAL(void);
extern void AD9850_RESET_SERIAL(void);
extern void AD9850_WR_SERIAL(unsigned char w0,double frequence);
extern void AD9850_INIT_PARREL(void);
extern void AD9850_RESET_PARREL(void);
extern void AD9850_WR_PARREL(unsigned char w0,double frequence);
#endif /* LED_H_ */
/*
* AD9850.c
*
* Created on: 2013-10-15
* Author: Allen
*/
#include "AD9850.h"
#include
void AD9850_INIT_SERIAL(void)
{
AD9850_W_CLK_IO_INIT;
AD9850_FQ_UP_IO_INIT;
AD9850_RESET_IO_INIT;
AD9850_BIT_DATA_IO_INIT;
}
void AD9850_RESET_SERIAL(void)
{
AD9850_W_CLK_L;
AD9850_FQ_UP_L;
//rest信号
AD9850_RESET_L;
AD9850_RESET_H;
AD9850_RESET_L;
//w_clk信号
AD9850_W_CLK_L;
AD9850_W_CLK_H;
AD9850_W_CLK_L;
//fq_up信号
AD9850_FQ_UP_L;
AD9850_FQ_UP_H;
AD9850_FQ_UP_L;
}
void AD9850_WR_SERIAL(unsigned char w0,double frequence)
{
unsigned char i,w;
long int y;
double x;
//计算频率的HEX值
x=4294967295/20;//适合125M晶振
//如果时钟频率不为20MHZ,修改该处的频率值,单位MHz !!!
frequence=frequence/1000000;
frequence=frequence*x;
y=frequence;
//写w4数据
w=(y>>=0);
for(i=0;i<8;i++)
{
// ad9850_bit_data=(w>>i)&0x01;
if((w>>i)&0x01)
AD9850_BIT_DATA_H;
else
AD9850_BIT_DATA_L;
AD9850_W_CLK_H;
AD9850_W_CLK_L;
}
//写w3数据
w=(y>>8);
for(i=0;i<8;i++)
{
if((w>>i)&0x01)
AD9850_BIT_DATA_H;
else
AD9850_BIT_DATA_L;
AD9850_W_CLK_H;
AD9850_W_CLK_L;
}
//写w2数据
w=(y>>16);
for(i=0;i<8;i++)
{
if((w>>i)&0x01)
AD9850_BIT_DATA_H;
else
AD9850_BIT_DATA_L;
AD9850_W_CLK_H;
AD9850_W_CLK_L;
}
//写w1数据
w=(y>>24);
for(i=0;i<8;i++)
{
if((w>>i)&0x01)
AD9850_BIT_DATA_H;
else
AD9850_BIT_DATA_L;
AD9850_W_CLK_H;
AD9850_W_CLK_L;
}
//写w0数据
w=w0;
for(i=0;i<8;i++)
{
if((w>>i)&0x01)
AD9850_BIT_DATA_H;
else
AD9850_BIT_DATA_L;
AD9850_W_CLK_H;
AD9850_W_CLK_L;
}
//移入始能
AD9850_FQ_UP_H;
AD9850_FQ_UP_L;
}
void AD9850_INIT_PARREL(void)
{
AD9850_W_CLK_IO_INIT;
AD9850_FQ_UP_IO_INIT;
AD9850_RESET_IO_INIT;
1DIR=0xff;
}
void AD9850_RESET_PARREL(void)
{
AD9850_W_CLK_L;
AD9850_FQ_UP_L;
//rest信号
AD9850_RESET_L;
AD9850_RESET_H;
AD9850_RESET_L;
}
void AD9850_WR_PARREL(unsigned char w0,double frequence)
{
unsigned char w;
long int y;
double x;
//计算频率的HEX值
x=4294967295/20;//适合20M晶振
//如果时钟频率不为20MHZ,修改该处的频率值,单位MHz !!!
frequence=frequence/1000000;
frequence=frequence*x;
y=frequence;
//写w0数据
w=w0;
1OUT=w; //w0
AD9850_W_CLK_H;
AD9850_W_CLK_L;
//写w1数据
w=(y>>24);
1OUT=w; //w1
AD9850_W_CLK_H;
AD9850_W_CLK_L;
//写w2数据
w=(y>>16);
1OUT=w; //w2
AD9850_W_CLK_H;
AD9850_W_CLK_L;
//写w3数据
w=(y>>8);
1OUT=w; //w3
AD9850_W_CLK_H;
AD9850_W_CLK_L;
//写w4数据
w=(y>>0);
1OUT=w; //w4
AD9850_W_CLK_H;
AD9850_W_CLK_L;
//移入始能
AD9850_FQ_UP_H;
AD9850_FQ_UP_L;
}