原创
AD9851的驱动程序
2008-8-23 09:27
4119
3
4
分类:
软件与OS
//====================================================================
// Copyright (C), 2006, HUST.
// ----Filename: AD9851.c
// -Description: AD9851驱动
// -----History: 06/8/29 V1.0 Edit By L.F.
//====================================================================
//头文件
#include "SPCE061A.h"
//变量说明
unsigned long int Freq_Ctrl_Word = 0x051eb851; //频率控制字 先传低位再传高位
unsigned int Phase_Ctrl_Word = 0x0000; //相位控制字 先传低位再传高位
unsigned int Order_Ctrl_Word = 0x0000;//b32:0 6倍频关闭 b33b34:00 电源工作模式
//定义AD9851与SPCE061A的接口
#define M_DATA 0x0001
#define M_UD 0x0002
#define M_CLK 0x0004
#define Set_IOA_Bit(x) (*P_IOA_Data = *P_IOA_Buffer | x) //置高
#define Clear_IOA_Bit(x) (*P_IOA_Data = *P_IOA_Buffer & ~x) //置低
//====================================================================
// ----Function: void Init_AD9851(void)
// -Description: 初始化与AD9851连接的IO口
// --Parameters: 无
// ------Return: 无
// -------Notes: 不影响其他IO口
//====================================================================
void Init_AD9851(void)
{
*P_IOA_Dir |= (M_DATA + M_UD + M_CLK);
*P_IOA_Attrib |= (M_DATA + M_UD + M_CLK);
*P_IOA_Data &= ~(M_DATA + M_UD + M_CLK);
}
//====================================================================
// ----Function: void Write_AD9851(void)
// -Description: 向AD9851写入频率控制字,命令控制字和相位控制字
// --Parameters: 无
// ------Return: 无
// -------Notes: 无
//====================================================================
void Write_AD9851(void)
{
unsigned long int mask = 0x0001;
unsigned int i;
Clear_IOA_Bit(M_UD); //M_UD置低
//送32位频率控制字
for(i = 0;i < 32;i++)
{
Clear_IOA_Bit(M_CLK); //M_CLK置低
if(Freq_Ctrl_Word & mask)
{
Set_IOA_Bit(M_DATA);
}
else
{
Clear_IOA_Bit(M_DATA);
}
Set_IOA_Bit(M_CLK);
mask = mask << 1;
}
//送3位的命令控制字
mask = 0x0001;
for(i = 0;i < 3;i++)
{
Clear_IOA_Bit(M_CLK); //M_CLK置低
if(Order_Ctrl_Word & mask)
{
Set_IOA_Bit(M_DATA);
}
else
{
Clear_IOA_Bit(M_DATA);
}
Set_IOA_Bit(M_CLK);
mask = mask << 1;
}
//送5位相位控制字
mask = 0x0001;
for(i = 0;i < 5;i++)
{
Clear_IOA_Bit(M_CLK); //M_CLK置低
if(Phase_Ctrl_Word & mask)
{
Set_IOA_Bit(M_DATA);
}
else
{
Clear_IOA_Bit(M_DATA);
}
Set_IOA_Bit(M_CLK);
mask = mask << 1;
}
Set_IOA_Bit(M_UD); //M_UD置高 ,产生上升沿 ,频率更新使能,输出有效
}
//====================================================================
// End of AD9851.c
//====================================================================
用户461316 2008-8-23 12:33