《基于51的ads1115程序.docx》由会员分享,可在线阅读,更多相关《基于51的ads1115程序.docx(13页珍藏版)》请在优知文库上搜索。
1、*/_*功能:ADS1115单端输入检测电压】./;._*Cpu:STC12C5A60S2*m*/;_*ADC芯片:【ADS1115(2差分输入或者4单端输入)】*._二一*液晶.*/fLCD1602J*_-*/*.*ADC与单片机连接:SCkPLOzSDAiPl.1*.*/*一* 检测范围:0.004.99V*/#include/include#defineuintunsignedintftdefineucharunsignedchar#define_Nop()_nop_()i以下为LCDI602显示模块端口定义及函数声明*/sbit lcd_rs_port = Pl7;sbit lcd_r
2、w_port = P16;sbit lcd_en_port = P24;#define lcd_data_port PO*定义LCD控制端口*/67.9AB电压显示框架电压显示位置voidlcd_delay(ucharms);/LCD1602延时voidlcd_busy_wait();/LCD1602忙等待voidlcd_command_write(ucharcommand);/LCD1602命令字写入voidlcd_system_reset);/LCD1602初始化voidlcd_char_write(ucharx-poszy-pos,lcd-dat);/LCD1602字符写入voidlcd
3、_bad_check();/LCD1602坏点检查voidNum_to_Disp(uintNum);/LCD1602数据处理voidLcdDisp(uintnum);/LCD1602数据显示voiddelay_lms(uchar);/LCD1602延时Ims/*以下为ADSIII5模块端口定义及函数声明*/sbitSCL=P10;sbitSDA=P11;#defineTRUE1#defineFALSE0unsignedintConfig;unsigned int Result2;int D_ADS;ftdefine Accuracy 32768 char VCC = 4.78;unsigned
4、charWritebuff4zReadbuff3;转换的数字量定义ADC精度,ADS1115单端输入时15位/VCC,电压参考值/ADDR PIN -GND /ADDR PIN -VDD /ADDR PIN -SDA /ADDR PIN -SCL#defineADDRESS_O0x90#defineADDRESS_10x92#defineADDRESS_20x94#defineADDRESS_30x96POINTERREGISTER*/Convertion register /Config register /Lo_thresh register /HLthresh register#defi
5、nePointer_0#definePointer_lOXol#definePointer_22#definePointer_30x03/CONFIGREGISTER*/#defineOS_00x0000#defineOS_10x8000#define MUX_0#define MUX_1 ftdefine MUX_2#define MUX_3#define MUX_40x00000x10000x20000x30000x4000#define MUX_5 0x5000#define MUX_6 0x6000#define MUX_7 0x7000/ANp=AIN0z AINn=AINl /AN
6、p=AIN0z AINn=AIN3 AINP=AlN1, AINn=AIN3 /AINp=AIN2z AINn=AIN3 /AINp=AIN0, AINn=GND /ANp=AINlz AINn=GND /AINp=AIN2z AINn=GND /AINp=AIN3z AINn=GND#definePGA_00x0000/FS=6.144V#definePGA_10x0200/FS=4.096V#definePGA_20x0400/FS=2.048V#definePGA_30x0600/FS=1.024V#definePGA_40x0800/FS=0.512V#definePGA_5OxOAO
7、O/FS=0.256V#definePGA_6OxOCOO/FS=0.256V#definePGA_7OxOEOO/FS=0.256VftdefineMODE_.00x0000#defineMODE_10x0100#defineDR_00x0000/DataRate=8#defineDR_10x0020/DataRate=16#defineDR_20x0040/DataRate=32#defineDR_30x0060/DataRate=64#defineDR_40x0080/DataRate=128#defineDR_5OxOOAO/DataRate=250#defineDR_6OxOOCO/
8、DataRate=475#defineDR_7OxOOEO/DataRate=860#defineCOMP_MODE_00x0000#defineCOMP_MODE_10x0010ftdefineCOMP_POL_0OXoOOO# defineCoMP_POL_1OXoOO8# defineCOMP_LAT_0OXOOoO# defineCOMP_LAT_1OXoO40# defineCOMP_QUE_0OXoOOo# defineCOMP_QUE_1OXoOol# defineCOMP_QUE_2OXOoO2#defineCOMP_QUE_30x0003/*ADDRInitial*#defi
9、neADDRESSADDRESS_0/ADDRPIN-GND#defineADDRESS_WADDRESS10x00写地址#defineADDRESS_RADDRESS10x01读地址*#defineOSOS_1#defineMUX_A0MUX_4/ANp=AIN0,AINn=GND#defineMUX_A1MUX_5AINP=AlN1,AINn=GND#defineMUX_A2MUX_6/AINp=AIN2,AINn=GND#defineMUX_A3MUX_7/AINp=AIN3zAINn=GND#definePGAPGA_1/FS=6.144V#defineMODEMODE_1/Conti
10、nuousconversion#defineDRDR_7/DataRate=860#defineCOMP_QUECOMP_QUE_3*ConfigInitial*/modevoidDelay_us_15(void);voidDelay_ms_l(void);voidStartfvoid);功功能:延时能:完成HC的起始条件操作voidStop(void);功能:完成HC的终止条件操作voidACKvoid);功能:完成HC的主机应答操作voidNACK(void);功能:完成IIC的主机无应答操作unsignedcharCheck(void)能:检查从机的应答操作voidWrite_l_Byt
11、e(unsignedcharDataByte);unsignedcharWrite_N_Byte(unsignedchar*writebufferzunsignedcharn);unsignedcharRead_l_Byte(void);voidRead_N_Byte(unsignedint*readbuff,unsignedcharn);voidlnitADS1115(bitS_MUX_0,bitS_MUX_1);voidWriteWord(void);voidReadWord(void);unsignedintADS1115(bitS_MUX_0,bitS_MUX_1);写1个字节写N个字
12、节读1个字节读N个字节/ADS1115初始化写读/ADS1115取值/*/*主函数*_*/*/voidmain)unsignedintresult;Icd_system_reset();lcd_bad_check();/LCD1602初始化/LCD1602坏点检查while(l)(result=ADS1115(0,0);/ADS1115取值_AIN0/result=ADSIIl5(0,1);ADSIIl5取值_AIN1/result=ADSlII5(L0);ADSIII5取值_AIN2/result=ADS1115(1,1);/ADS1115取值一AIN31.cdDispfresuIt);LCDl602显示电压值)*_*以下为LCDl602显示模块函数定义*/voidlcd_delay(ucharms)*LCD1602延时*/(ucharj;while(m