首先看一下ADS1118.C文件
#include "ADS1118.H"
extern void DelayMs(unsigned int i);
unsigned char ADS1118_Read(unsigned char data1);
void ADS1118_Get_Voltage(void);
/*
初始化ADS1118器件
*/
void ADS1118_init(void)
{
u8 i=0;
ADS1118_CS_OUT; //CS配置为推挽输出
ADS1118_CLK_OUT; //CLK配置为推挽输出
ADS1118_IN_OUT; //配置为推挽输出
ADS1118_OUT_IN; //配置为数字输入模式
SET_ADS1118_CS;
CLR_ADS1118_CLK;
DelayMs(10);
CLR_ADS1118_IN;
i=200;
while(i--);
CLR_ADS1118_CS;
ADS1118_Get_Voltage();
}
/*
SPI为全双工通信方式
*/
unsigned char ADS1118_Read(unsigned char data1)
{
unsigned char i;
unsigned char temp;
unsigned char Din;
temp = data1;
for(i=0;i<8;i++)
{
Din = Din<<1;
if(0x80&temp)
SET_ADS1118_IN;
else
CLR_ADS1118_IN;
DelayMs(1);
SET_ADS1118_CLK;
DelayMs(1);
if(ADS1118_OUT)
Din |= 0x01;
DelayMs(1);
CLR_ADS1118_CLK;
DelayMs(1);
temp = (temp<<1);
}
return Din;
}
/*
ADS1118_Voltage : 用来记录ADS1118采样的电压
*/
float ADS1118_Voltage;
void ADS1118_Get_Voltage(void)
{
unsigned int i=0;
unsigned char Data_REG_H,D