资源简介
AD5420的STC单片机C语言驱动,已调试通过
代码片段和文件信息
#include “AD5420.h“
/*
输入移位寄存器位24位
由8位地址位和24位数据组成
在SCLK的上升沿MSB开始被载入
最高30MHz通信速率
LANCH位高电平时锁存数据
在LANCH为高电平期间所有输入数据无效
如果SCLK脉冲数量不足或者多于24个置位LANCH数据同样无效
数据输出在AD5420的SDO引脚上输出
*/
//用户函数
//初始化
void ad5420_init()
{
unsigned char buf[3];
AD5420_clear=0; //复位引脚清零
AD5420_sclk =0;
AD5420_sdin =0;
AD5420_latch=0;
ad5420_delay(10);
AD5420_latch=1;
ad5420_delay(10);
AD5420_latch=0; //产生LANCH的脉冲清除移位寄存器中多余的数据
buf[2] = ADDRESS_RESET; //复位寄存器
buf[1] = 0x00; //DATA_High_8bit----Disable Slew Rate
buf[0] = 0x01; //DATA_LOW_8bit
WriteToAD5420(buf); //Write 551005 to SHIFT REGISTER to write 1005 to control register
ad5420_delay(100);
buf[2] = ADDRESS_CONTROL; //控制寄存器
buf[1] = 0x3F; //DATA_High_8bit----Disable Slew Rate
buf[0] = 0x15; //DATA_LOW_8bit
WriteToAD5420(buf); //Write 551005 to SHIFT REGISTER to write 1005 to control register
}
void ad5420_setValue(unsigned int value)
{
unsigned char buf[3];
AD5420_clear=0; //复位引脚清零
AD5420_sclk =0;
AD5420_sdin =0;
AD5420_latch=0;
ad5420_delay(10);
AD5420_latch=1;
ad5420_delay(10);
AD5420_latch=0; //产生LANCH的脉冲清除移位寄存器中多余的数据
buf[2] = ADDRESS_DATA; //数据寄存器
buf[1] = value>>8; //DATA_High_8bit
buf[0] = value; //DATA_LOW_8bit
WriteToAD5420(buf); //Write 01 99 66H to SHIFT REGISTER to write 99 66 to DATA REGISTER
}
//底层函数
void ad5420_delay (unsigned int length)
{
while (length >0)
length--;
}
//---------------------------------
//void WriteToAD5420(unsigned char countunsigned char *Buf);
//---------------------------------
//Funct
评论
共有 条评论