《基于msp430单片机ADS1115程序的设计与开发.docx》由会员分享,可在线阅读,更多相关《基于msp430单片机ADS1115程序的设计与开发.docx(15页珍藏版)》请在第一文库网上搜索。
1、ADS1115 模块:#include#define uchar unsigned char#define uint unsigned int#define SCL_H Pl OUT |= BITO#define SCL_LP1OUT &= -BITO#define SDA_H Pl OUT |= BIT1/SDA改成输入模式/SDA变回输出模式/SDA的位值#define SDA LP1OUT &=-BITl#define SDAJn P1DIR &=BIT1#define SDA_out Pl DIR |= BIT1#define SDA valPHN&BITl#defme TRUE#de
2、fine FALSEvoid delay(void)uchar i;for(i = 0;i ,如函数名称:功 能:参 数:返回值:/start完成lie的起始条件操作无无&,“4$ & 4 如, $ 如& Jfvoid start(void)SCL_H;SDA H;delay();SDA L;delay();SCL_L;delay();f/ rj* rj rjw rj* rj* rj rj* rj rj rj rj* rjw rj* rj rj rj rj rj rj rj rj* rj rj rj rj rj函数名称:stop功能:完成lie的终止条件操作参数:无返回值:无rj*p rj*r
3、j* rj rj .void stop(void)SDA_L;delay();SCL H;delayO;SDA H;delay();/.J/ rTw Tw rTw Tw rTw rTw rTw rTw Tw 1 *Tw 7 rTw 7w rTw Tw rTw rTw rTw 丫 Tw *Tw rTw rTw 7w rTw Tw rTw rTw rTw 函数名称:mack功能:完成1IC的主机应答操作参数:无返回值:无Jrj* rj rjw rj rj rj rjw rj rj rj rj rj* rj rjw rj rj rj rjw rj rj rjw rj rj rj rj* rjw rj
4、 rj rj rjw rj rj /void mack(void)SDA_L;,NOP(); _NOP();SCL H;delay();SCL_L;_NOP();_NOP();SDA H;delay();/* *!* *!“ *4* *“ *! “* *!* *! *“ *! *“ *! * *! * *! * *! *“ *!J #TvT%#T #Tv函数名称:mnack功能:完成IIC的主机无应答操作参数:无返回值:无* *! * * *! * *! * *! * *! * *! * *! * *! * * *! * *! * “ *! * *! /7 T 7 T 7 T7 、.TTT%T
5、 , 如函数名称:功 能:参 数:返回值:/check检查从机的应答操作无从机是否有应答:1-有,0-无* * * * * * * * * * * * * * * * * /T 7 T 7 T #T #Tv #7 #T#T% T 7 T #7 #T#T%7 TT T T% fvoid ack()uchar i;i=0;SDA in;SCL H;delay ();while(PHN&BITl)&(i .” .N .以.47“ *2 /卜 、 rj rj% ,卜 rjw 乂、r|% rj* 卜 rjr|% rj rj% ,卜 rjwrite 1向nc总线发送一个i无无kJ* 7”7” 7. 7.7
6、” 7“7” kJ* k1 7. !”7” 7. 7” /“卜 q, q,“卜 q, rj* q,“卜 、r|% rjrj% “卜 q,q,“卜 q, rj/卜r|% “卜rj% 卜 q,“卜 rj /卜r|% Jvoid write 1 (void)SDA H;delay();SCL_H;delay();SCL L;delay();1/ *“ *4* * “ *! “ * * “ * “ * * * * *J #Tv#T #Tv函数名称:writeO功能:向nc总线发送一个0参数:无返回值:无* * * * * * * * * * * * * * * * * “ * * /7 T 7 T 7
7、 T7 、.T TT%T T #T% /void writeO(void)SDA L;delay();SCL_H;delay();SCL L;delay();1/ “ * * * “ * “ * * * * *J #TvT% #T #Tv函数名称:write 1 byte功能:向nc总线发送一个字节的数据参数:wdata-发送的数据返回值:无* * * * * * * * * * * “ * * * * * “ * “ /T 7 T 72 T% 7 T 7 T 7 T 7 T 0;i-)(if(wdata & 0x80) write 1();elsewriteO();wdata = 1;SDA
8、 H;,NOP();/*“ *4* *“ *! “*J #Tv#T #Tv函数名称:read 1 byte功能:从nc总线读取一个字节参数:无返回值:读取的数据* * * * * * * * * * * * * * * * * “ * * /7 T 7 T 7 T、T% 7 T TT%T T #T% Juchar read 1 byte(void)(uchar rdata = 0x00,i;uchar flag;for(i = ();i 8;i+)SDA H;SCL_H;SDA in;flag = SDA_val;rdata = 1;if(flag) rdata |= 0x01;SDA_out
9、;SCL_L; 显示模块:#include#includelcd.h#includeiic.h#includeHmath.hHvoid Send(unsigned char type,unsigned char transdata);void Ini_Lcd(void);void Clear_GDRAM(void);void Disp_HZ(unsigned char addr,unsigned char * pt,unsigned char num);void delay_Nms(unsigned int n);void delay_Nus(unsigned int n);void dela
10、y_lms(void);#define CPU_F (double)8000000)#define delay_us(x) _delay_cycles(long)(CPU_F*(double)x/1000000.0) 延时 uS#define delay_ms(x) delay_cycles(long)(CPU_F*(double)x/1 ()()().() 延时 mS#define uchar unsigned char#define uint unsigned int#define address 0x90#define config 0x01#define conversion 0x00/表示选择通道0表示选择通道1/表示选择通道2表示选择通道2# define Lsiwei 0xE3# definechannel_00# definechannel_l1# definechannel_22# definechannel_33uchar jieguo51;uchar dianya3;void