//========================AD9850.h=============================///*--------------------------------------------AD9850驱动程序----------------------------------------------*/#ifndef__AD9850_H#define__AD9850_H/*选择数据通信方式,只能选择一个*///#defineMODE_SEIAL//串行模式#defineMODE_PARALLEL//并行模式#defineAD9850_SYSTEM_COLCK100000000/*AD9850控制和数据引脚定义*/#defineAD9850_CONTROL_PORTGPIOA#defineAD9850_FQUDGPIO_Pin_2#defineAD9850_WCLKGPIO_Pin_3#defineAD9850_RSTGPIO_Pin_4#ifdefMODE_PARALLEL//并行模式数据口0~7#defineAD9850_DATA_PORTGPIOC#endif#ifdefMODE_SEIAL//串行模式数据口#defineAD9850_DATAGPIO_Pin_5#defineAD9850_DATA_Write_1GPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_DATA,Bit_SET)#defineAD9850_DATA_Write_0GPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_DATA,Bit_RESET)#endif#defineAD9850_WCLK_SETGPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_WCLK,Bit_SET)#defineAD9850_WCLK_CLRGPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_WCLK,Bit_RESET)#defineAD9850_FQUD_SETGPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_FQUD,Bit_SET)#defineAD9850_FQUD_CLRGPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_FQUD,Bit_RESET)#defineAD9850_RST_SETGPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_RST,Bit_SET)#defineAD9850_RST_CLRGPIO_WriteBit(AD9850_CONTROL_PORT,AD9850_RST,Bit_RESET)/*串行模式操作函数*/#ifdefMODE_SEIALexternvoidAD9850_Reset_Sreial(void);externvoidAD9850_Write_Serial(unsignedcharW0,unsignedlongfreq);#endif/*并行模式操作函数*/#ifdefMODE_PARALLELexternvoidAD9850_Reset_Parallel(void);externvoidAD9850_Write_Parallel(unsignedcharW0,unsignedlongfreq);#endifexternvoidInit_AD9850(void);#endif/*AD8950_H*///==================================================================////=========================AD9850.c=================================//#includestm32f10x_lib.h#includeAD9850.h/********************************************函数名称:AD9850_Delay功能:AD9850延时函数参数:z-延时长度返回值:无*********************************************/voidAD9850_Delay(unsignedintz){for(;z0;z--){;}}/*--------------------并行模式-----------------------*/#ifdefMODE_PARALLEL/********************************************函数名称:AD9850_Reset_Parallel功能:在并行模式下复位AD9850参数:无返回值:无*********************************************/voidAD9850_Reset_Parallel(void){AD9850_WCLK_CLR;AD9850_FQUD_CLR;//RST信号AD9850_RST_CLR;AD9850_RST_SET;AD9850_Delay(0xFFFF);AD9850_RST_CLR;}/********************************************函数名称:AD9850_Write_Parallel功能:在并行模式下写AD9850寄存器参数:W0-W0寄存器的值freq-频率值返回值:无*********************************************/voidAD9850_Write_Parallel(unsignedcharW0,unsignedlongfreq){unsignedcharwdata;unsignedlongy=(unsignedlong)(4294967295/AD9850_SYSTEM_COLCK);y*=freq;wdata=W0;//写w0GPIO_Write(AD9850_DATA_PORT,wdata);AD9850_WCLK_SET;AD9850_WCLK_CLR;wdata=y24;//写w1GPIO_Write(AD9850_DATA_PORT,wdata);AD9850_WCLK_SET;AD9850_WCLK_CLR;wdata=y16;//写w2GPIO_Write(AD9850_DATA_PORT,wdata);AD9850_WCLK_SET;AD9850_WCLK_CLR;wdata=y8;//写w3GPIO_Write(AD9850_DATA_PORT,wdata);AD9850_WCLK_SET;AD9850_WCLK_CLR;wdata=y0;//写w4GPIO_Write(AD9850_DATA_PORT,wdata);AD9850_WCLK_SET;AD9850_WCLK_CLR;AD9850_FQUD_SET;//移入使能AD9850_Delay(0xFFFF);AD9850_FQUD_CLR;}#endif/*MODE_PARALLEL*//*------------------------并行模式-------------------------*//*---------------------------------------------------------*//*------------------------串行模式-------------------------*/#ifdefMODE_SEIAL/********************************************函数名称:AD9850_Reset_Sreial功能:在串行模式下复位AD9850参数:无返回值:无*********************************************/voidAD9850_Reset_Sreial(void){AD9850_WCLK_CLR;AD9850_FQUD_CLR;//RST信号AD9850_RST_CLR;AD9850_RST_SET;AD9850_Delay(0xFFFF);AD9850_RST_CLR;//WCLK信号AD9850_WCLK_CLR;AD9850_WCLK_SET;AD9850_Delay(0xFFFF);AD9850_WCLK_CLR;//FQUD信号AD9850_FQUD_CLR;AD9850_FQUD_SET;AD9850_Delay(0xFFFF);AD9850_FQUD_CLR;}/********************************************函数名称:AD9850_Write_Serial功能:在串行模式下写AD9850寄存器参数:W0-W0寄存器的值freq-频率值返回值:无*********************************************/voidAD9850_Write_Serial(unsignedcharW0,unsignedlongfreq){unsignedchari,wdata;unsignedlongy;y=(unsignedlong)268435456.0/AD9850_SYSTEM_COLCK*freq;wdata=y0;//写w4for(i=0;i8;i++){if(wdata&0x01)AD9850_DATA_Write_1;elseAD9850_DATA_Write_0;AD9850_WCLK_SET;wdata=1;AD9850_WCLK_CLR;}wdata=y8;//写w3for(i=0;i8;i++){if(wdata&0x01)AD9850_DATA_Write_1;elseAD9850_DATA_Write_0;AD9850_WCLK_SET;wdata=1;AD9850_WCLK_CLR;}wdata=y16;//写w2for(i=0;i8;i++){if(wdata&0x01)AD9850_DATA_Write_1;elseAD9850_DATA_Write_0;AD9850_WCLK_SET;wdata=1;AD9850_WCLK_CLR;}wdata=y24;//写w1for(i=0;i8;i++){if(wdata&0x01)AD9850_DATA_Write_1;elseAD9850_DATA_Write_0;AD9850_WCLK_SET;wdata=1;AD9850_WCLK_CLR;}wdata=W0;//写w0for(i=0;i8;i++){if(wdata&0x01)AD9850_DATA_Write_1;elseAD9850_DATA_Write_0;AD9850_WCLK_SET;wdata=1;AD9850_WCLK_CLR;}AD9850_FQUD_SET;//移入使能AD9850_Delay(0xFFFF);AD9850_FQUD_CLR;}#endif/*MODE_SERIAL*//*------------------------串行模式-------------------------*//*---------------------------------------------------------*//********************************************函数名称:Init_AD9834功能:初始化AD9834参数:无返回值:无*********************************************/voidInit_AD9850(void){#ifdefMODE_SEIAL//串行模式GPIO_InitT