/home/daqweb/fgddaq/c8051/Protocols/SHT7x_protocol.h File Reference


Defines

#define SHT7x_DELAY   5
#define SHT7x_SHORT_DELAY   0.3
#define ACK   0
#define NACK   1
#define ERROR   0
#define DONE   1

Functions

void SHT7x_Init (int humsen)
void SHT7x_ClockOnce (int humsen)
void SHT7x_ConnectionReset (int humsen)
void SHT7x_TransStart (int humsen)
unsigned char SHT7x_FCS_Step (unsigned int msg, unsigned char fcs) reentrant
unsigned char SHT7x_WriteByte (unsigned char dataToSend, int humsen)
unsigned char SHT7x_ReadByte (unsigned char read_flag, int humsen)
void SHT7x_ClockOnce2 (int humsen)

Variables

sbit SHT7x_DATA1 = SHT_DATA1
sbit SHT7x_SCK1 = SHT_SCK1

Define Documentation

#define ACK   0

#define DONE   1

#define ERROR   0

#define NACK   1

#define SHT7x_DELAY   5

#define SHT7x_SHORT_DELAY   0.3


Function Documentation

void SHT7x_ClockOnce ( int  humsen  ) 

00143                                 {
00144   if(humsen==1)
00145   {
00146     SHT7x_SCK1 = 0;
00147     delay_us(SHT7x_DELAY);
00148     SHT7x_SCK1 = 1;
00149     delay_us(SHT7x_DELAY);
00150     SHT7x_SCK1 = 0;
00151   }
00152 #ifdef MORETHANONEHUM
00153   else if(humsen==2)
00154   {
00155     SHT7x_SCK2 = 0;
00156     delay_us(SHT7x_DELAY);
00157     SHT7x_SCK2 = 1;
00158     delay_us(SHT7x_DELAY);
00159     SHT7x_SCK2 = 0;
00160   }
00161 #endif
00162 }

void SHT7x_ClockOnce2 ( int  humsen  ) 

void SHT7x_ConnectionReset ( int  humsen  ) 

00076                                       {
00077   unsigned char i;
00078   if(humsen==1)
00079   {
00080     //Initial state
00081     SHT7x_DATA1=1; 
00082     SHT7x_SCK1=0; 
00083   }
00084 #ifdef MORETHANONEHUM
00085   else if(humsen==2)
00086   {
00087     SHT7x_DATA2=1;
00088     SHT7x_SCK2=0;
00089   }
00090 #endif
00091   for(i=0;i<9;i++) {           //9 SCK cycles
00092       SHT7x_ClockOnce(humsen);
00093     }
00094 //  SHT7x_TransStart(humsen);    //transmission start
00095 }        

unsigned char SHT7x_FCS_Step ( unsigned int  msg,
unsigned char  fcs 
)

00058                                                                             {
00059    return SHT7x_FCS_data[(msg ^ fcs)];
00060 }

void SHT7x_Init ( int  humsen  ) 

00064                            {
00065   
00066   SHT7x_ConnectionReset(humsen);
00067 }

unsigned char SHT7x_ReadByte ( unsigned char  read_flag,
int  humsen 
)

00207                                                                  {
00208 
00209   signed char i;
00210   unsigned char dataReceived=0, din=0;
00211   if(humsen==1)
00212   {
00213     SHT7x_DATA1 = 1; //release SHT7x_DATA line
00214     //NW Read when the clock line is high 
00215     for (i = 7; i >= 0; i--) { 
00216       din = SHT7x_DATA1;
00217       SHT7x_ClockOnce(humsen);
00218       dataReceived |= (din << i);  
00219     }
00220 
00221     SHT7x_DATA1 = read_flag;    //Sending ACK/NACK. In case of ACK pull the SHT7x_DATA line low
00222     SHT7x_ClockOnce(humsen);    //The 9th clock cycle
00223     SHT7x_DATA1 = 1;            //Release the SHT7x_DATA line
00224 
00225 
00226   }
00227 #ifdef MORETHANONEHUM
00228   else if(humsen==2)
00229   {
00230     SHT7x_DATA2=1; //release SHT7x_DATA line
00231     //NW Read when the clock line is high 
00232     for (i = 7; i >= 0; i--) { 
00233       din = SHT7x_DATA2;
00234       SHT7x_ClockOnce(humsen);
00235       dataReceived |= (din << i);  
00236     }
00237 
00238     SHT7x_DATA2 = read_flag;    //Sending ACK/NACK. In case of ACK pull the SHT7x_DATA line low
00239     SHT7x_ClockOnce(humsen);    //The 9th clock cycle
00240     SHT7x_DATA2 = 1;            //Release the SHT7x_DATA line
00241   }
00242 #endif
00243   return dataReceived;
00244 }

void SHT7x_TransStart ( int  humsen  ) 

00104                                  {
00105   if(humsen==1) {
00106     //Initial state
00107     SHT7x_DATA1=1; 
00108     delay_us(SHT7x_DELAY);
00109     SHT7x_SCK1=1;
00110     delay_us(SHT7x_DELAY);
00111     SHT7x_DATA1=0;
00112     delay_us(SHT7x_DELAY);
00113     SHT7x_SCK1=0;
00114     delay_us(SHT7x_DELAY);    //low pulse, but in the sample code, it used 3 _nop_();
00115     SHT7x_SCK1=1;
00116     delay_us(SHT7x_DELAY);
00117     SHT7x_DATA1=1;
00118     delay_us(SHT7x_DELAY);
00119     SHT7x_SCK1=0;
00120   }
00121 #ifdef MORETHANONEHUM
00122   else if(humsen==2) {
00123     //Initial state
00124     SHT7x_DATA2=1; 
00125     delay_us(SHT7x_DELAY);
00126     SHT7x_SCK2=1;
00127     delay_us(SHT7x_DELAY);
00128     SHT7x_DATA2=0;
00129     delay_us(SHT7x_DELAY);
00130     SHT7x_SCK2=0;
00131     delay_us(SHT7x_DELAY);    //low pulse, but in the sample code, it used 3 _nop_();
00132     SHT7x_SCK2=1;
00133     delay_us(SHT7x_DELAY);
00134     SHT7x_DATA2=1;
00135     delay_us(SHT7x_DELAY);
00136     SHT7x_SCK2=0;
00137   }
00138 #endif
00139 }

unsigned char SHT7x_WriteByte ( unsigned char  dataToSend,
int  humsen 
)

00167                                                                    {
00168 
00169   signed char xdata i;
00170   unsigned char xdata status;
00171   if(humsen == 1) {  
00172       for(i = 7; i >= 0; i--) {
00173         SHT7x_DATA1 = (dataToSend >> i) & 0x01;
00174       SHT7x_ClockOnce(humsen);  
00175     }
00176 
00177     SHT7x_DATA1 = 1;          //Release SHT7x_DATA line
00178     delay_us(10);
00179     SHT7x_ClockOnce(humsen);  // ACK reception of the CMD
00180     SHT7x_DATA1 = 1;          //Release SHT7x_DATA line
00181 
00182   }
00183 #ifdef MORETHANONEHUM
00184   else if(humsen==2)
00185   {
00186       for(i = 7; i >= 0; i--) {
00187         SHT7x_DATA2 = (dataToSend >> i) & 0x01;
00188       SHT7x_ClockOnce(humsen);  
00189     }
00190 
00191     SHT7x_DATA2 = 1;          //Release SHT7x_DATA line
00192     delay_us(10);
00193     SHT7x_ClockOnce(humsen);  // ACK reception of the CMD
00194     SHT7x_DATA2 = 1;          //Release SHT7x_DATA line
00195 
00196 
00197   }  
00198 #endif
00199   if (status == NACK)         //1 in case of No acknowledge
00200      return ERROR;             
00201   return DONE;
00202 }


Variable Documentation

sbit SHT7x_DATA1 = SHT_DATA1

sbit SHT7x_SCK1 = SHT_SCK1


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7