下面一段是我编写的ADS1251数据采集代码,不知道是否正确,请各位大神指点一二,,,,,
signed long ADS1251_Read(void)
{
unsigned int i;
signed long voltage;
unsigned long lADC=0;
ADS1251_SCLK_0;
//等待开始
while(!(rP2_IN & ADS1251_DOUT));
//24clk:624us
while((rP2_IN & ADS1251_DOUT)); //DRDY 24CLK
//6clk:156us
while(!(rP2_IN & ADS1251_DOUT)); //DRDY 6CLK
Delay(150);//延时150uS 用的3.6864M钟振
for(i = 0; i < 24; i++) //开始读取BIT0-BIT23数据
{
ADS1251_SCLK_1; Delay(1);//延时1uS
lADC <<= 1;
if (rP2_IN&ADS1251_DOUT) //ADS1251_DOUT;
lADC++;
ADS1251_SCLK_0; Delay(1);
}
if((lADC & 0x800000)) //判断正负数
{
lADC=(lADC-0x000001)^0xffffff;
fushu=1;
}
else
{
fushu=0;
}
voltage = lADC ;
return voltage;
}