⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad9854_parallel.c

📁 AD9854的51控制程序
💻 C
字号:
//***************************************************************************//
//AD9854并行程序
//***************************************************************************//

#include "SPCE061V004.h"
#include "BitOperation.h"

#define AD9854_UDCLK	0
#define AD9854_WR		1
#define AD9854_RD		2
#define AD9854_FDATA	3
#define AD9854_OSK		4
#define AD9854_RESET	5

void AD9854_SendByte(unsigned int Adress, unsigned int Data)
{
	WrSegHIOA(Adress);
	WrSegLIOA(Data);
	WrBitIOB(AD9854_WR,0);
	WrBitIOB(AD9854_WR,1);
}

void AD9854_Init(void)//AD9854并行初始化和控制寄存器初始化
{
	WrBitIOB(AD9854_RESET,1);
	__asm("nop");//延时
	__asm("nop");//延时
	__asm("nop");//延时
	__asm("nop");//延时
	WrBitIOB(AD9854_RESET,0);
	WrBitIOB(AD9854_RD,1);
	WrBitIOB(AD9854_WR,1);
	AD9854_SendByte(0x1d,0x10);
	AD9854_SendByte(0x1e,0x48);
	AD9854_SendByte(0x1f,0x00);
	AD9854_SendByte(0x20,0x00);
	WrBitIOB(AD9854_UDCLK,1);
	WrBitIOB(AD9854_UDCLK,0);
}

void AD9854_SetFreq_I(unsigned long FreqI)//AD9854通道I频率控制
		//最大频率43.8MHz,频率大于此值时,可能会出现计算溢出错误
{
	unsigned long FreqWord[6];
	unsigned int cout,Adress=0x09;
	
	FreqWord[0]=FreqI*0x59;
	FreqWord[1]=FreqWord[0]/0x100;
	FreqWord[0]%=0x100;
	
	FreqWord[1]=FreqWord[1]+FreqI*0x62;
	FreqWord[2]=FreqWord[1]/0x100;
	FreqWord[1]%=0x100;
	
	FreqWord[2]=FreqWord[2]+FreqI*0x10;
	FreqWord[3]=FreqWord[2]/0x100;
	FreqWord[2]%=0x100;
	
	FreqWord[4]=FreqWord[3]/0x100;
	FreqWord[3]%=0x100;
	
	FreqWord[5]=FreqWord[4]/0x100;
	FreqWord[4]%=0x100;
	
	for(cout=0;cout<6;cout++)
	{
		AD9854_SendByte(Adress,(unsigned int)FreqWord[cout]);
		Adress--;
	}
	
	WrBitIOB(AD9854_UDCLK,1);
	WrBitIOB(AD9854_UDCLK,0);
}

void AD9854_SetShape_I(unsigned int ShapeI)//AD9854通道I幅度控制
{
	unsigned int ShapeIH;
	ShapeIH=ShapeI>>8;
	ShapeI&=0xff;
	
	AD9854_SendByte(0x20,0x20);
	AD9854_SendByte(0x21,ShapeIH);
	AD9854_SendByte(0x22,ShapeI);
	
	WrBitIOB(AD9854_UDCLK,1);
	WrBitIOB(AD9854_UDCLK,0);
}

void AD9854_SetShape_Q(unsigned int ShapeQ)//AD9854通道Q幅度控制
{
	unsigned int ShapeQH;
	ShapeQH=ShapeQ>>8;
	ShapeQ&=0xff;
	
	AD9854_SendByte(0x20,0x20);
	AD9854_SendByte(0x23,ShapeQH);
	AD9854_SendByte(0x24,ShapeQ);
	
	WrBitIOB(AD9854_UDCLK,1);
	WrBitIOB(AD9854_UDCLK,0);
}

void AD9854_SetPhase_I(unsigned int PhaseI)//AD9854通道I相位控制
{
	unsigned int PhaseIH;
	PhaseIH=PhaseI>>8;
	PhaseI&=0xff;
	
	AD9854_SendByte(0x00,PhaseIH);
	AD9854_SendByte(0x00,PhaseI);
	
	WrBitIOB(AD9854_UDCLK,1);
	WrBitIOB(AD9854_UDCLK,0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -