|
楼主 |
发表于 2016-3-21 17:59:06
|
显示全部楼层
在此贴出一个算是可用的程序和原理图,供用到的人参考:
union
{
long ADC_DATA_LONG;
struct
{
unsigned char lbyte; // Low byte
unsigned char mbyte; // Middle byte
unsigned char hbyte; // High byte
unsigned char zbyte; // Zero byte
}bytes;
}AD_NOW;
unsigned char ADS1232_Read_Byte(void)
{
unsigned char i = 8;
unsigned char rbyte;
while(i--)
{
rbyte <<= 1;
ADC_CLK_1;
if(ADC_DATA_READ)rbyte += 1;
ADC_CLK_0;
}
return rbyte;
}
unsigned char ADS1232_Ready(void)
{
if(ADC_DATA_READ)
{
return 1;
}
else
{
return 0;
}
}
void ADS1232_Offset_Cal(void)
{
while(ADS1232_Ready() == 0);
while(ADS1232_Ready() == 1);
AD_NOW.bytes.hbyte = ADS1232_Read_Byte();
AD_NOW.bytes.mbyte = ADS1232_Read_Byte();
AD_NOW.bytes.lbyte= ADS1232_Read_Byte();
AD_NOW.bytes.zbyte = 0;
ADC_CLK_1;
ADC_CLK_0;
ADC_CLK_1;
ADC_CLK_0;
ADC_CLK_1;
ADC_CLK_0;
}
//SPEED=10/80 channel=0 通道0 channel=1 通道1 channel=2 测温
void ADS1232_Init(unsigned char gain,unsigned char speed,unsigned char channel)
{
ADC_RST_0;
delay_ms(10);
ADC_RST_1;
switch (gain)
{
case 1: ADC_GAIN1_0; ADC_GAIN0_0; break;
case 2: ADC_GAIN1_1; ADC_GAIN0_0; break;
case 64: ADC_GAIN1_0; ADC_GAIN0_1; break;
case 128: ADC_GAIN1_1; ADC_GAIN0_1; break;
default: ADC_GAIN1_0; ADC_GAIN0_0; break;
}
if (channel==0){ADC_A0_0;ADC_TEMP_0;}
else if(channel==1){ADC_A0_1;ADC_TEMP_0;}
else if(channel==2){ADC_TEMP_1;}
if(speed == 80) {ADC_SPD_1;}
else {ADC_SPD_0;}
ADC_CLK_0;
ADS1232_Offset_Cal();
}
void ReadAds1232( void )
{
while(ADS1232_Ready() == 0);
while(ADS1232_Ready() == 1);
AD_NOW.bytes.hbyte = ADS1232_Read_Byte();
AD_NOW.bytes.mbyte = ADS1232_Read_Byte();
AD_NOW.bytes.lbyte= ADS1232_Read_Byte();
AD_NOW.bytes.zbyte = 0;
ADC_CLK_1;
ADC_CLK_0;
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|