256抽头精密数字电位器AD5160测试程序
/********* STC12C5A60S2平台AD5160数字电位器程序 时钟:外部12M 晶振
电位器串联外部电阻连接为可变电阻模式,若不串外部电阻直接接参考电压源即工作为数字电位计模式
*NOTE:作为可变电阻模式与外部电阻串联时存在一定程度容差,若所串电阻大于AD5160本身满量程电阻(型号有5K\10K\50K\100K)10倍以上则此容差才可忽略 *****/
/*AD5160.H*/
#ifndef _AD5160_H_
#define _AD5160_H_
#include
#include
typedef unsigned char uchar;
typedef unsigned int uint;
sbit CPCS = P3^2; //数字电位器AD5160的片选CS ,低电平有效
sbit SDI = P3^4; //数字电位器AD5160的数据SDI
sbit SCK = P3^5; //数字电位器AD5160的时钟SCLK
void AD5160_init() //AD5160初始化
{
CPCS = 1;
SCK = 0
SDI = 1;
}
void set_AD5160(uchar dat) //设定从W 抽头到B 端的抽头数,以10K 版本的为 { //例电阻为R w B = 60+39*rdac 其中W 抽头接触电阻为60Ω
uchar i,rdac=0; CPCS = 1; rdac = dat; //RDAC为写入AD5160 内部8位radc 寄存器数据 SCK = 0; _nop_();_nop_();_nop_();_nop_(); SCK = 1; //SCK在CS 拉低前触发一个时钟
_nop_();_nop_(); SCK = 0; _nop_(); CPCS = 0; //拉低CS 启动数据写入 for(i=0;i
SCK = 1;
_nop_();
SCK = 0;
}
CPCS = 1;
_nop_();
SCK = 1;
_nop_();_nop_();
SCK = 0;
_nop_();
}
#endif //片选拉高后SCK 送一个结束时钟,这点很重要