Ö»Òª°´¶¨Òå½Ó¿Ú£¬ÏÂÔØ´úÂ룬ÎÞÐè×öÈκθĶ¯£¬¼´¿É¶Á³öÊý¾Ý~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~¹¦ÄÜ˵Ã÷:SHT10ÓëÉÏλ»ú£¨´®¿Úµ÷ÊÔÖúÊÖ£©µÄÎÂʪ¶ÈÏÔʾKeilC³ÌÐò΢´¦ÀíÆ÷:STC89C52±àÒë»·¾³:KeiluVisionV4~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;*************************************************************/#includereg52.h//Microcontrollerspecificlibrary,e.g.portdefinitions#includeintrins.h//Keillibrary(isusedfor_nop()_operation)#includemath.h//Keillibrary#includestdio.h//Keillibrary/*************¶¨Òå½Ó¿Ú******************P2.6------SCK(SHT10)P2.7------DATA(SHT10)*****************************************/sbitSCK=P2^6;//¶¨ÒåͨѶʱÖӶ˿ÚsbitDATA=P2^7;//¶¨ÒåͨѶÊý¾Ý¶Ë¿Útypedefunion{unsignedinti;//¶¨ÒåÁËÁ½¸ö¹²ÓÃÌåfloatf;}value;enum{TEMP,HUMI};//ö¾Ù²âÁ¿Î¶Ȼòʪ¶È#definenoACK0//ÓÃÓÚÅжÏÊÇ·ñ½áÊøͨѶ#defineACK1//½áÊøÊý¾Ý´«Êä//adrcommandr/w#defineSTATUS_REG_W0x06//00000110#defineSTATUS_REG_R0x07//00000111#defineMEASURE_TEMP0x03//00000011#defineMEASURE_HUMI0x05//00000101#defineRESET0x1e//00011110/****************¶¨Ò庯Êý****************/voids_transstart(void);//Æô¶¯´«Ê亯Êývoids_connectionreset(void);//Á¬½Ó¸´Î»º¯Êýchars_write_byte(unsignedcharvalue);//SHT10дº¯Êýchars_read_byte(unsignedcharack);//SHT10¶Áº¯Êýchars_measure(unsignedchar*p_value,unsignedchar*p_checksum,unsignedcharmode);//²âÁ¿ÎÂʪ¶Èº¯Êývoidcalc_sht10(float*p_humidity,float*p_temperature);//ÎÂʪ¶È²¹³¥floatcalc_dewpoint(floath,floatt);//¼ÆË㶵ã//chars_softreset(void);//chars_read_statusreg(unsignedchar*p_value,unsignedchar*p_checksum);//chars_write_statusreg(unsignedchar*p_value);/*--------------------------------------;Ä£¿éÃû³Æ:s_write_byte();;¹¦ÄÜ:SHT10дº¯Êý;Õ¼ÓÃ×ÊÔ´:--;²ÎÊý˵Ã÷:--;´´½¨ÈÕÆÚ:2012.04.10;°æ±¾:FV1.0(º¯Êý°æ±¾FunctionVersion);ÐÞ¸ÄÈÕÆÚ:--;ÐÞ¸Ä˵Ã÷:--;-------------------------------------*/chars_write_byte(unsignedcharvalue)//writesabyteontheSensibusandcheckstheacknowledge{unsignedchari,error=0;for(i=0x80;i0;i/=2)//shiftbitformasking{if(i&value)DATA=1;//maskingvaluewithi,writetoSENSI-BUSelseDATA=0;SCK=1;//clkforSENSI-BUS_nop_();_nop_();_nop_();//pulswithapprox.5usSCK=0;}DATA=1;//releaseDATA-lineSCK=1;//clk#9forackerror=DATA;//checkack(DATAwillbepulleddownbySHT11)SCK=0;returnerror;//error=1incaseofnoacknowledge}/*--------------------------------------;Ä£¿éÃû³Æ:s_read_byte();;¹¦ÄÜ:SHT10¶Áº¯Êý;Õ¼ÓÃ×ÊÔ´:--;²ÎÊý˵Ã÷:--;´´½¨ÈÕÆÚ:2012.04.10;°æ±¾:FV1.0(º¯Êý°æ±¾FunctionVersion);ÐÞ¸ÄÈÕÆÚ:--;ÐÞ¸Ä˵Ã÷:--;-------------------------------------*/chars_read_byte(unsignedcharack)//readsabyteformtheSensibusandgivesanacknowledgeincaseofack=1{unsignedchari,val=0;DATA=1;//releaseDATA-linefor(i=0x80;i0;i/=2)//shiftbitformasking{SCK=1;//clkforSENSI-BUSif(DATA)val=(val|i);//readbitSCK=0;}DATA=!ack;//incaseofack==1pulldownDATA-LineSCK=1;//clk#9forack_nop_();_nop_();_nop_();//pulswithapprox.5usSCK=0;DATA=1;//releaseDATA-linereturnval;}/*--------------------------------------;Ä£¿éÃû³Æ:s_transstart();;¹¦ÄÜ:Æô¶¯´«Ê亯Êý;Õ¼ÓÃ×ÊÔ´:--;²ÎÊý˵Ã÷:--;´´½¨ÈÕÆÚ:2012.04.10;°æ±¾:FV1.0(º¯Êý°æ±¾FunctionVersion);ÐÞ¸ÄÈÕÆÚ:--;ÐÞ¸Ä˵Ã÷:--;-------------------------------------*/voids_transstart(void)//generatesatransmissionstart//_____________//DATA:|_______|//______//SCK:___||___||______{DATA=1;SCK=0;//Initialstate_nop_();SCK=1;_nop_();DATA=0;_nop_();SCK=0;_nop_();_nop_();_nop_();SCK=1;_nop_();DATA=1;_nop_();SCK=0;}/*--------------------------------------;Ä£¿éÃû³Æ:s_connectionreset();;¹¦ÄÜ:Á¬½Ó¸´Î»º¯Êý;Õ¼ÓÃ×ÊÔ´:--;²ÎÊý˵Ã÷:--;´´½¨ÈÕÆÚ:2012.04.10;°æ±¾:FV1.0(º¯Êý°æ±¾FunctionVersion);ÐÞ¸ÄÈÕÆÚ:--;ÐÞ¸Ä˵Ã÷:--;-------------------------------------*/voids_connectionreset(void)//communicationreset:DATA-line=1andatleast9SCKcyclesfollowedbytransstart//_____________________________________________________________//DATA:|_______|//_______________//SCK:__||__||__||__||__||__||__||__||__||______||___||______{unsignedchari;DATA=1;SCK=0;//Initialstatefor(i=0;i9;i++)//9SCKcycles{SCK=1;SCK=0;}s_transstart();//transmissionstart}/*//----------------------------------------------------------------------------------chars_softreset(void)//----------------------------------------------------------------------------------//resetsthesensorbyasoftreset{unsignedcharerror=0;s_connectionreset();//resetcommunicationerror+=s_write_byte(RESET);//sendRESET-commandtosensorreturnerror;//error=1incaseofnoresponseformthesensor}//----------------------------------------------------------------------------------chars_read_statusreg(unsignedchar*p_value,unsignedchar*p_checksum)//----------------------------------------------------------------------------------//readsthestatusregisterwithchecksum(8-bit){unsignedcharerror=0;s_transstart();//transmissionstarterror=s_write_byte(STATUS_REG_R);//sendcommandtosensor*p_value=s_read_byte(ACK);//readstatusregister(8-bit)*p_checksum=s_read_byte(noACK);//readchecksum(8-bit)returnerror;//error=1incaseofnoresponseformthesensor}//----------------------------------------------------------------------------------chars_write_statusreg(unsignedchar*p_value)//--------------------------------------------