ADS1115程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "HEAD.h"
void main( void )
{
uchar Value;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
int_clk();
Write_COnfig(0x40,0xE3); //写配置寄存器
Value=Read_Conversion_MSB();
LCD_show_DA(Value);
}
void Write_Byte(uchar Data) //所有写时间片操作至少需要60us
{
uchar i=0;
SCL_0;
SCL_OUT; //时钟信号为输出
SDA_0;
SDA_OUT; //数据信号为输出
delay_us(5);
for(i=0;i<8;i++)
{
SCL_0;
delay_us(5);
if(Data&0x80==1)
SDA_1;
else
SDA_0;
delay_us(1);
SCL_1;
delay_us(2);
Data<<=1;
}
SCL_0;
delay_us(5);
SDA_0;
delay_us(1);
SCL_1;
delay_us(2);
}
uchar Read_Byte(void)
{
uchar i = 0;
uchar Data=0;
SCL_0;
SCL_OUT; //时钟信号为输出
SDA_1;
SDA_IN; //数据信号为输入
for(i=0; i<8; i++)
{
Data<<=1;
SCL_0;
delay_us(5);
if(1==SDA_PIN)
Data|=0x01;
delay_us(1);
SCL_1;
delay_us(2);
}
SCL_1;
delay_us(5);
return Data;
}
void Write_COnfig(uchar MSB,uchar LSB) //写配置寄存器
{
Write_Byte(ADDRESS_WRITE);
Write_Byte(POINT_Config_register);
Write_Byte(MSB); Write_Byte(LSB);
}
void Write_Lo_Thresh(uchar LSB) //写低阀值寄存器
{
Write_Byte(ADDRESS_WRITE);
Write_Byte(POINT_Lo_register);
Write_Byte(LSB);
}
void Write_Hi_Thresh(uchar MSB) //写高阀值寄存器
{
Write_Byte(ADDRESS_WRITE);
Write_Byte(POINT_Hi_register);
Write_Byte(MSB);
}
void Read_Conversion(void) //指向转换寄存器
{
Write_Byte(ADDRESS_READ);
Write_Byte(POINT_Conversion_register);
}
uchar Read_Conversion_MSB(void) //只读转换寄存器高8位
{
uchar MSB;
Read_Conversion(); //指向转换寄存器
Write_Byte(ADDRESS_READ);
MSB=Read_Byte();
delay_us(20);
return MSB;
}
uint Read_Conversion_M_L(void) //读转换寄存器高,低8位
{
uint M_L_SB;
uchar LSB,MSB;
Read_Conversion(); //指向转换寄存器
Write_Byte(ADDRESS_READ);
MSB=Read_Byte();
LSB=Read_Byte();
M_L_SB=(uint)MSB<<8+LSB;
delay_us(20);
return M_L_SB;
}