基于某51地ads1115程序编写

实用标准文案

/*------------------------------------------------------------------------------------------------------------------------------------------*/

/*--*************************功能: 【ADS1115单端输入检测电压】********************--*/ /*--*************************CPU: 【STC12C5A60S2】*******************************--*/ /*--*************************ADC芯片:【ADS1115(2差分输入或4单端输入)】***********--*/ /*--*************************液晶: 【LCD1602】************************************--*/ /*--*************************ADC与单片机连接:【SCL:P1.0 , SDA:P1.1】*******************--*/ /*--*************************检测范围:【0.00~4.99V】*********************************--*/

/*----------------------------------------------------------------------------------------------------------------------------------------*/ #include #include

#define uint unsigned int #define uchar unsigned char #define _Nop() _nop_()

/*------------------------以下为LCD1602显示模块端口定义及函数声明-----------------------*/ sbit lcd_rs_port = P1^7; /*定义LCD控制端口*/ sbit lcd_rw_port = P1^6; sbit lcd_en_port = P2^4; #define lcd_data_port P0

unsigned char num_char_table[] = {\

unsigned char Lcd_Dis1_table[] = {\ //电压显示框架 unsigned char pos_char_table[] = {\ //电压显示位置

void lcd_delay(uchar ms); //LCD1602 延时 void lcd_busy_wait(); //LCD1602 忙等待 void lcd_command_write(uchar command); //LCD1602 命令字写入 void lcd_system_reset(); //LCD1602 初始化 void lcd_char_write(uchar x_pos,y_pos,lcd_dat); //LCD1602 字符写入 void lcd_bad_check(); //LCD1602 坏点检查 void Num_to_Disp(uint Num); //LCD1602 数据处理 void LcdDisp(uint num); //LCD1602 数据显示 void delay_1ms(uchar x); //LCD1602 延时1ms

/*------------------------以下为ADS1115模块端口定义及函数声明--------------------------*/

sbit SCL = P1^0; sbit SDA = P1^1;

#define TRUE 1 #define FALSE 0

unsigned int Config;

文档大全

实用标准文案

unsigned char Writebuff[4],Readbuff[3]; unsigned int Result[2];

int D_ADS; //转换的数字量

#define Accuracy 32768 //定义ADC精度,ADS1115单端输入时15位 char VCC = 4.78; //VCC,电压参考值

#define ADDRESS_0 0x90 //ADDR PIN ->GND #define ADDRESS_1 0x92 //ADDR PIN ->VDD #define ADDRESS_2 0x94 //ADDR PIN ->SDA #define ADDRESS_3 0x96 //ADDR PIN ->SCL

/************POINTER REGISTER*****************/ #define Pointer_0 0x00 //Convertion register #define Pointer_1 0x01 //Config register #define Pointer_2 0x02 //Lo_thresh register #define Pointer_3 0x03 //Hi_thresh register

/************CONFIG REGISTER*****************/ #define OS_0 0x0000 #define OS_1 0x8000

#define MUX_0 0x0000 //AINp=AIN0, AINn=AIN1 #define MUX_1 0x1000 //AINp=AIN0, AINn=AIN3 #define MUX_2 0x2000 //AINp=AIN1, AINn=AIN3 #define MUX_3 0x3000 //AINp=AIN2, AINn=AIN3 #define MUX_4 0x4000 //AINp=AIN0, AINn=GND #define MUX_5 0x5000 //AINp=AIN1, AINn=GND #define MUX_6 0x6000 //AINp=AIN2, AINn=GND #define MUX_7 0x7000 //AINp=AIN3, AINn=GND

#define PGA_0 0x0000 //FS=6.144V #define PGA_1 0x0200 //FS=4.096V #define PGA_2 0x0400 //FS=2.048V #define PGA_3 0x0600 //FS=1.024V #define PGA_4 0x0800 //FS=0.512V #define PGA_5 0x0A00 //FS=0.256V #define PGA_6 0x0C00 //FS=0.256V #define PGA_7 0x0E00 //FS=0.256V

#define MODE_0 0x0000 #define MODE_1 0x0100

#define DR_0 0x0000 //Data Rate = 8 #define DR_1 0x0020 //Data Rate = 16 #define DR_2 0x0040 //Data Rate = 32 #define DR_3 0x0060 //Data Rate = 64

文档大全

实用标准文案

#define DR_4 0x0080 //Data Rate = 128 #define DR_5 0x00A0 //Data Rate = 250 #define DR_6 0x00C0 //Data Rate = 475 #define DR_7 0x00E0 //Data Rate = 860

#define COMP_MODE_0 0x0000 #define COMP_MODE_1 0x0010

#define COMP_POL_0 0x0000 #define COMP_POL_1 0x0008

#define COMP_LAT_0 0x0000 #define COMP_LAT_1 0x0040

#define COMP_QUE_0 0x0000 #define COMP_QUE_1 0x0001 #define COMP_QUE_2 0x0002 #define COMP_QUE_3 0x0003

//*************ADDR Initial********************/ #define ADDRESS ADDRESS_0 //ADDR PIN ->GND #define ADDRESS_W ADDRESS|0x00 //写地址 #define ADDRESS_R ADDRESS|0x01 //读地址

/*************Config Initial*********************/ #define OS OS_1

#define MUX_A0 MUX_4 //AINp=AIN0, AINn=GND #define MUX_A1 MUX_5 //AINp=AIN1, AINn=GND #define MUX_A2 MUX_6 //AINp=AIN2, AINn=GND #define MUX_A3 MUX_7 //AINp=AIN3, AINn=GND #define PGA PGA_1 //FS=6.144V

#define MODE MODE_1 //Continuous conversion mode #define DR DR_7 //Data Rate = 860 #define COMP_QUE COMP_QUE_3

void Delay_us_15 (void);

void Delay_ms_1 (void); //功 能:延时

void Start(void); //功 能:完成IIC的起始条件操作 void Stop(void); //功 能:完成IIC的终止条件操作 void ACK(void); //功 能:完成IIC的主机应答操作

void NACK(void); //功 能:完成IIC的主机无应答操作 unsigned char Check(void);//功 能:检查从机的应答操作

void Write_1_Byte(unsigned char DataByte); //写 1个字节 unsigned char Write_N_Byte(unsigned char *writebuffer,unsigned char n); //写 N个字节 unsigned char Read_1_Byte(void); //读 1个字节 void Read_N_Byte(unsigned int *readbuff,unsigned char n); //读 N个字节

文档大全

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4