当前位置:首页 > 基于单片机控制的多功能控制温湿度 - 图文
_nop_(); DATA=1; _nop_(); SCK=0; }
/*-------------------------------------- ;模块名称:s_connectionreset(); ;功 能:连接复位函数 ;-------------------------------------*/ void s_connectionreset(void)
// 通讯复位: DATA-line=1 and at least 9 SCK cycles followed by transstart
// _____________________________________________________ ________ // |_______|
// _ _ _ _ _ _ _ _ _ ___ ___
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ {
unsigned char i; //初始状态 DATA=1;
SCK=0;
for(i=0;i<9;i++) //9 SCK cycles
DATA:
{ SCK=1; SCK=0; }
s_transstart(); //启动传输 }
/*-------------------------------------- ;模块名称:s_write_byte(); ;功 能:SHT10写函数 ;-------------------------------------*/ char s_write_byte(unsigned char value)
//---------------------------------------------------------------------------------- // writes a byte on the Sensibus and checks the acknowledge {
unsigned char i,error=0;
for (i=0x80;i>0;i/=2) //shift bit for masking {
if (i & value) DATA=1; //masking value with i , write to SENSI-BUS
else DATA=0;
SCK=1; //clk for SENSI-BUS _nop_();_nop_();_nop_(); //pulswith approx. 3 us
SCK=0; }
DATA=1; //release DATA-line SCK=1; //clk #9 for ack
error=DATA; //check ack (DATA will be pulled down by SHT10),DATA在第9个上升沿将被SHT10自动下拉为低电平。 _nop_();_nop_();_nop_(); SCK=0;
DATA=1; //release DATA-line
return error; //error=1 in case of no acknowledge //返回:0成功,1失败 }
/*-------------------------------------- ;模块名称:s_read_byte(); ;功 能:SHT10读函数 ;-------------------------------------*/ char s_read_byte(unsigned char ack)
// reads a byte form the Sensibus and gives an acknowledge in case of \ {
unsigned char i,val=0;
DATA=1; //release DATA-line for (i=0x80;i>0;i/=2) //shift bit for masking { SCK=1; //clk for SENSI-BUS
if (DATA) val=(val | i); //read bit _nop_();_nop_();_nop_(); //pulswith approx. 3 us SCK=0; }
if(ack==1)DATA=0; //in case of \pull down DATA-Line
else DATA=1; //如果是校验(ack==0),读取完后结束通讯
_nop_();_nop_();_nop_(); //pulswith approx. 3 us SCK=1; //clk #9 for ack _nop_();_nop_();_nop_(); //pulswith approx. 3 us SCK=0;
_nop_();_nop_();_nop_(); //pulswith approx. 3 us DATA=1; //release DATA-line return val; }
/*-------------------------------------- ;模块名称:s_measure(); ;功 能:测量温湿度函数 ;-------------------------------------*/
char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
共分享92篇相关文档