[原创修改]AD5421程序的一个例程
0赞
发表于 2011/10/25 22:51:42
阅读(4333)
今天写一个关于AD转化的例子,硬件平台是基于 ADuC7026 + AD5421 。
#include
#include "ADuC7026Driver.h"
#include "AD5421.h"
int main()
{
long int cstr = 0;
unsigned short RegisterData = 0;
long int RegAddress;
unsigned char rdata[2]={0,0};
ADuC7026_Initiate();
AD5421_Initiate();
while(1)
{ /*
读回寄存器值,第11位一定是1,目的是读到预置的哪个寄存器值,同时关闭spi看门狗 */
cstr = WR | CONTROL_REGISTER | 0x7800;
WriteToAD5421ViaSpi(&cstr);
/*
输出范围是4mA-20mA,在这个范围才能满足测试的需求,低于4mA的默认为是4mA,高于20mA的默认为是20mA */
cstr = WR | DAC_REGISTER | 0x8000; //output current = 12mA
WriteToAD5421ViaSpi(&cstr);
cstr = WR | OFFSET_ADJUST_REGISTER | 0x8000; //寄存器偏移量的默认值
WriteToAD5421ViaSpi(&cstr);
cstr = WR | GAIN_ADJUST_REGISTER | 0xFFFF; //获取寄存器的默认值
cstr = WR | GAIN_ADJUST_REGISTER | 0xFFFF; //获取寄存器的默认值
WriteToAD5421ViaSpi(&cstr);
//readback the selected registers
mA
rdata[0]=(unsigned char)(RegisterData & 0x00FF);
rdata[1]=(unsigned char)((RegisterData & 0xFF00)>>8);
putchar(rdata[1]);
putchar(rdata[0]);
RegAddress = DAC_REGISTER;
ReadFromAD5421ViaSpi(&RegisterData,RegAddress);
rdata[1]=(unsigned char)((RegisterData & 0xFF00)>>8);
putchar(rdata[1]);
putchar(rdata[0]);
RegAddress = DAC_REGISTER;
ReadFromAD5421ViaSpi(&RegisterData,RegAddress);
rdata[0]=(unsigned char)(RegisterData & 0x00FF);
rdata[1]=(unsigned char)((RegisterData & 0xFF00)>>8);
putchar(rdata[1]);
putchar(rdata[0]);
rdata[1]=(unsigned char)((RegisterData & 0xFF00)>>8);
putchar(rdata[1]);
putchar(rdata[0]);
}
return 0;
}
程序由于参考了ADI的官方程序,同时根据我的硬件平台做了一些参数的调整,写出来大家一起交流,我自己很满意。