|
#include <iom16.h>
#include "delay.h"
#include "AD9854.h"
#define uchar unsigned char
#define uint unsigned int
#define AD9854_CON PORTD
#define AD9854_DDR DDRD
#define AD_SCLK_0 AD9854_CON&=0xfe
#define AD_SDIO_0 AD9854_CON&=0xfd
#define AD_CS_0 AD9854_CON&=0xfb
#define AD_M_RST_0 AD9854_CON&=0x07
#define IO_RESET_0 AD9854_CON&=0xef
#define Up_data_clk_0 AD9854_CON&=0xdf
#define AD_SCLK_1 AD9854_CON|=0x01
#define AD_SDIO_1 AD9854_CON|=0x02
#define AD_CS_1 AD9854_CON|=0x04
#define AD_M_RST_1 AD9854_CON|=0x08
#define IO_RESET_1 AD9854_CON|=0x10
#define Up_data_clk_1 AD9854_CON|=0x20
/****初始化AD9854****/
void Initial()
{
AD9854_DDR = 0xff;
AD_M_RST_1;
delay_nm(10);
AD_M_RST_0;
IO_RESET_1;
delay_m();
IO_RESET_0;
Up_data_clk_0;
Write_instruction_byte(0x07);
Write_One_Byte(0x14);
//Write_One_Byte(0x66);
Write_One_Byte(0x44);
Write_One_Byte(0x02);
Write_One_Byte(0x20);
Up_data_clk_1;
Up_data_clk_0;
}
void Write_One_Byte(unsigned char Byte)
{
uchar i = 0;
AD_SCLK_0;
for(i=0;i<8;i++)
{
AD_SCLK_0;
if((Byte&0x80)==0x80)
{
AD_SDIO_1;
}
else
{
AD_SDIO_0;
}
AD_SCLK_1;
Byte = Byte<<1;
}
AD_SCLK_0;
}
void Write_instruction_byte(unsigned char Loc)
{
Write_One_Byte(Loc);
}
void Read_instruction_byte(unsigned char Loc)
{
Loc|=0x80;
Write_One_Byte(Loc);
}
/****设置频率转换字 1 ****/
void Write_fre_1(unsigned long long Set_fre_1) //FTW = (Desired Output Frequency*2N)/SYSCLK
{
Up_data_clk_0;
uchar A_0, A_1, A_2, A_3, A_4, A_5;
A_0 = Set_fre_1 % 256;
Set_fre_1 = Set_fre_1 / 256;
A_1 = Set_fre_1 % 256;
Set_fre_1 = Set_fre_1 / 256;
A_2 = Set_fre_1 % 256;
Set_fre_1 = Set_fre_1 / 256;
A_3 = Set_fre_1 % 256;
Set_fre_1 = Set_fre_1 / 256;
A_4 = Set_fre_1 % 256;
Set_fre_1 = Set_fre_1 / 256;
A_5 = Set_fre_1 % 256;
Write_instruction_byte(Fre_1);
Write_One_Byte(A_5);
Write_One_Byte(A_4);
Write_One_Byte(A_3);
Write_One_Byte(A_2);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/****设置频率转换字 2 ****/
void Write_fre_2(unsigned long long Set_fre_2)
{
Up_data_clk_0;
uchar A_0, A_1, A_2, A_3, A_4, A_5;
A_0 = Set_fre_2 % 256;
Set_fre_2 = Set_fre_2 / 256;
A_1 = Set_fre_2 % 256;
Set_fre_2 = Set_fre_2 / 256;
A_2 = Set_fre_2 % 256;
Set_fre_2 = Set_fre_2 / 256;
A_3 = Set_fre_2 % 256;
Set_fre_2 = Set_fre_2 / 256;
A_4 = Set_fre_2 % 256;
Set_fre_2 = Set_fre_2 / 256;
A_5 = Set_fre_2 % 256;
Write_instruction_byte(Fre_2);
Write_One_Byte(A_5);
Write_One_Byte(A_4);
Write_One_Byte(A_3);
Write_One_Byte(A_2);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/****设置相位转换字 1 ****/
void Write_pha_1(unsigned int Pha_1)
{
Up_data_clk_0;
uchar A_0, A_1;
A_0 = Pha_1 % 256;
Pha_1 = Pha_1 / 256;
A_1 = Pha_1 % 256;
Write_instruction_byte(Phase_1);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/****设置相位转换字 2 ****/
void Write_pha_2(unsigned int Pha_2)
{
Up_data_clk_0;
uchar A_0, A_1;
A_0 = Pha_2 % 256;
Pha_2 = Pha_2 / 256;
A_1 = Pha_2 % 256;
Write_instruction_byte(Phase_2);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/**********************I输出幅度 *************************
共有14bits控制输出幅度 (Bits 15, 14, 13, 12 don not care)
**********************************************************/
void Shaped_keying_mul_I(unsigned int Mul)
{
Up_data_clk_0;
uchar A_0, A_1;
A_0 = Mul % 256;
Mul = Mul / 256;
A_1 = Mul % 256;
Write_instruction_byte(OSK_I);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/**********************Q输出幅度 *************************
共有14bits控制输出幅度 (Bits 15, 14, 13, 12 don not care)
**********************************************************/
void Shaped_keying_mul_Q(unsigned int Mul)
{
Up_data_clk_0;
uchar A_0, A_1;
A_0 = Mul % 256;
Mul = Mul / 256;
A_1 = Mul % 256;
Write_instruction_byte(OSK_Q);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/**** 三角频率字 ****/
void DFW_fre(unsigned long long DFW)
{
Up_data_clk_0;
uchar A_0, A_1, A_2, A_3, A_4, A_5;
A_0 = DFW % 256;
DFW = DFW / 256;
A_1 = DFW % 256;
DFW = DFW / 256;
A_2 = DFW % 256;
DFW = DFW / 256;
A_3 = DFW % 256;
DFW = DFW / 256;
A_4 = DFW % 256;
DFW = DFW / 256;
A_5 = DFW % 256;
Write_instruction_byte(Del_fre);
Write_One_Byte(A_5);
Write_One_Byte(A_4);
Write_One_Byte(A_3);
Write_One_Byte(A_2);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/**** 三角频率字 ****/
void Ramp_rate_clk(unsigned long Ramp)
{
Up_data_clk_0;
uchar A_0, A_1, A_2;
A_0 = Ramp % 256;
Ramp = Ramp / 256;
A_1 = Ramp % 256;
Ramp = Ramp / 256;
A_2 = Ramp % 256;
Write_instruction_byte(Ramp_rat);
Write_One_Byte(A_2);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/****更新时钟频率 ****/
void Update_clk(unsigned long Clk_date)
{
Up_data_clk_0;
uchar A_0, A_1, A_2, A_3;
A_0 = Clk_date % 256;
Clk_date = Clk_date / 256;
A_1 = Clk_date % 256;
Clk_date = Clk_date / 256;
A_2 = Clk_date % 256;
Clk_date = Clk_date / 256;
A_3 = Clk_date % 256;
Write_instruction_byte(Up_clk);
Write_One_Byte(A_3);
Write_One_Byte(A_2);
Write_One_Byte(A_1);
Write_One_Byte(A_0);
Up_data_clk_1;
Up_data_clk_0;
}
/********** 写AD9854控制寄存器 *******************
参数说明:MODE:0x00: single-tone mode
0x01: FSK mode
0x02: ramped FSK mode
0x03: chrip mode
0x04: BPSK mode
MULT: pll倍频器,可以设定4 ~ 20
当用pll倍频器时bit_21一定设定为'0'
PD : 设定 power down 模式,依照手册33页设定
0x00: 没有省电模式
0x10: 比较器省电
0x14: 比较器省电,Q输出省电
0x18: 比较器省电,全部输出省电
OSK_EN : '1' 使能
Up_clk: 外部使能 '0'
内部是能 '1'
**************************************************/
void Write_con_byte(unsigned char Mode, unsigned char Mult,
unsigned char PD, unsigned char Osk_en,
unsigned char Clk)
{
Up_data_clk_0;
Write_instruction_byte(Con_byte);
Write_One_Byte(PD);
if(Mult==0)
{
Write_One_Byte(0x64); // 手册上默认值
}
else
{
Write_One_Byte(Mult | 0x40);
}
Write_One_Byte(Mode | Clk);
// if(Osk_en==0)
// {
// Write_One_Byte();
// }
// else
// {
// Write_One_Byte();
// }
Write_One_Byte(0x20);
Up_data_clk_1;
Up_data_clk_0;
}