资源简介
TI公司的24AD转换芯片ADS1210程序,该程序通过调试,运行正确。
代码片段和文件信息
#include
#include
#include
#define N 5
sbit ADC_SCLK = P1^3;
sbit ADC_SDIO = P1^2;
sbit ADC_SDOUT = P1^1;
sbit ADC_nDRDY = P1^0; //init0
bit ADC_Data_nDRDY; // 数据准备好标志位
void Init_ADS1210(void);
void Write_One_Byte(unsigned char dbuf);
unsigned char Read_One_Byte(void);
void delay(unsigned char conter);
void ADS1210_init(void)
{
//unsigned char i;
ADC_SCLK = 0;
ADC_SCLK = 1;
delay(64); //25.6 ~ 40 uS (32uS)
ADC_SCLK = 0;
delay(2); //>0.5 uS (1.0uS)
ADC_SCLK = 1;
delay(160); //51.2 ~ 90uS (79uS)
ADC_SCLK = 0;
delay(2); //>0.5 uS (1.0uS)
ADC_SCLK = 1;
delay(250); //102.4 ~ 120 uS (112uS)
ADC_SCLK = 0;
ADC_nDRDY = 1;
while (ADC_nDRDY==0)
;
while (ADC_nDRDY==1)
;
delay(2);
Write_One_Byte(0x64); //写入INSR命令01100100写CMR命令
delay(2);
Write_One_Byte(0x32); //CMR高字节BIAS = 0REFO = 0DF = 1U/B = 1 BD = MSB = 0SDL = 1 CMR3 = 00110010
Write_One_Byte(0xa4); //幕后校准(MD2 MD1 MD0 = 1 0 1)GAIN=2(G2 G1 G0 = 0 0 1)CH1 = CH2 = 0 CMR2 = 10100100
Write_One_Byte(0x6f); //TMR=8(SF2 SF1 SF0=0 1 1) CMR1 = 01100111
Write_One_Byte(0x41); //CMR低字节转换频率为10Hz有效位为21bits CMR0 = 10100000
delay(2);
ADC_nDRDY=1;
}
//*******************************************************************
// prototype : void Write_One_Byte(unsigned char com)
// parameter : -
// return : -
// function : 向ADS1210写入一字节数据
//*******************************************************************
void Write_One_Byte(unsigned char dbuf)
{
unsigned char count;
ADC_SDIO = 0;
_nop_();_nop_();_nop_();
for (count=0;count<8;count++)
{
ADC_SCLK=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
ADC_SDIO = (bit)(dbuf & 0x80);
dbuf <<= 1;
_nop_();_nop_();
ADC_SCLK=0;
_nop_();_nop_();_nop_();_nop_();_nop_();
}
ADC_SCLK=0;
}
//*******************************************************************
// prototype : unsigned char Read_One_Byte(void)
// parameter : -
// return : -
// function : 从ADS1210读取一字节数据
//*******************************************************************
unsigned char Read_One_Byte(void)
{
unsigned char count;
unsigned char data AdData;
//AdData = 0;
ADC_SDOUT = 1; //准
评论
共有 条评论