- /-------------------------------------------------------------------------------
- -AD9851.h
- -------------------------------------------------------------------------------/
- #include "DSP28_Device.h"
- //AD9851的I/O控制口宏定义
- #define DDS_W_CLK GpioDataRegs.GPADAT.bit.GPIOA12
- #define DDS_FQ_UD GpioDataRegs.GPADAT.bit.GPIOA13
- #define DDS_RESET GpioDataRegs.GPADAT.bit.GPIOA14
- #define DDS_D7 GpioDataRegs.GPADAT.bit.GPIOA15
- //AD9851相关函数申明
- void AD9851_Init(void);
- void Write_AD9851(Uint32 dds);
- void AD9851_Change(Uint32 freq);
- /-------------------------------------------------------------------------------
- -AD9851.c
- -------------------------------------------------------------------------------/
- #include "DSP28_Device.h"
- //AD9851初始化
- void AD9851_Init(void)
- {
- unsigned int i;
- unsigned int Serial_Mode = 0x03;
- EALLOW;
- //作为一般I/O口
- GpioMuxRegs.GPAMUX.bit.TCLKINA_GPIOA12=0;
- GpioMuxRegs.GPAMUX.bit.C1TRIP_GPIOA13 =0;
- GpioMuxRegs.GPAMUX.bit.C2TRIP_GPIOA14 =0;
- GpioMuxRegs.GPAMUX.bit.C3TRIP_GPIOA15 =0;
- //选择I/O口作为输出
- GpioMuxRegs.GPADIR.bit.GPIOA12=1;
- GpioMuxRegs.GPADIR.bit.GPIOA13=1;
- GpioMuxRegs.GPADIR.bit.GPIOA14=1;
- GpioMuxRegs.GPADIR.bit.GPIOA15=1;
- EDIS;
- DDS_W_CLK=0;
- DDS_FQ_UD=0;
- DDS_RESET=0;
- DDS_RESET=1;
- DelayUs(10000);
- DDS_RESET=0;
- DelayUs(10000);
- //配置串行方式
- for (i = 0;i < 8;i++)
- {
- DDS_W_CLK=0;
- if (Serial_Mode & 0x01)
- {
- DDS_D7=1;
- }
- else
- {
- DDS_D7=0;
- }
- DDS_W_CLK=1;
- Serial_Mode = Serial_Mode >> 1;
- DelayUs(1000);
- }
- DDS_FQ_UD=1;
- DelayUs(2000);
- DDS_FQ_UD=0;
- DDS_W_CLK=0;
- }
- //频率
- void AD9851_Change(Uint32 freq)
- {
- Uint32 dds;
- dds = freq * 23.860929422 ;
- Write_AD9851(dds);
- }
- //写数据
- void Write_AD9851(Uint32 dds)
- {
- unsigned int i;
- DDS_W_CLK=0;
- DDS_FQ_UD=0;
- for (i = 0;i < 40;i++)
- {
- DDS_W_CLK=0;
- DelayUs(2000);
- if((dds&0x00000001)||(i==32)) //取数据,6倍频使能
- {
- DDS_D7=1;
- }
- else
- {
- DDS_D7=0;
- }
- DDS_W_CLK=1;
- DelayUs(2000);
- dds = dds >> 1;
- }
- DDS_FQ_UD=1;
- DDS_W_CLK=0;
- DelayUs(2000);
- DDS_FQ_UD=0;
- }
暂无评论,赶紧抢沙发吧