基于msp430f149单片机的温湿度传感器sht1x驱动程序_第1页
基于msp430f149单片机的温湿度传感器sht1x驱动程序_第2页
基于msp430f149单片机的温湿度传感器sht1x驱动程序_第3页
基于msp430f149单片机的温湿度传感器sht1x驱动程序_第4页
基于msp430f149单片机的温湿度传感器sht1x驱动程序_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

基于 MSP430F149 单片机的温湿度传感器 SHT1X 驱动程序 #include “msp430x14x.h“ /头文件 #include “SHT1X.h“ #define _nop_() _NOP() /float iAdResultMM; /- / modul-var 温湿度传感器 SHT10 驱动程序开始 /- /- char s_write_byte(unsigned char value) /- / writes a byte on the Sensibus and checks the acknowledge unsigned char i,error=0; DATA_OutDIR(); for (i=0x80;i0;i/=2) /shift bit for masking if (i /DATA=1 masking value with i , write to SENSI-BUS else Clear_DATA(); /DATA=0 Set_CLK(); /SCK=1 clk for SENSI-BUS _nop_();_nop_();_nop_(); /pulswith approx. 5 us Clear_CLK(); /SCK=0 Set_DATA(); /DATA=1 release DATA-line DATA_InDIR(); Set_CLK(); /SCK=1 clk #9 for ack /DATA_InDIR(); error=P1IN / error=DATA check ack (DATA will be pulled down by SHT11) DATA_OutDIR(); Clear_CLK(); /SCK=0 if(error) return 1; return 0; /error=1 in case of no acknowledge /- char s_read_byte(unsigned char ack) /- / reads a byte form the Sensibus and gives an acknowledge in case of “ack=1“ unsigned char i,val=0; DATA_OutDIR(); Set_DATA(); /DATA=1 release DATA-line DATA_InDIR(); for (i=0x80;i0;i/=2) /shift bit for masking Set_CLK(); /SCK=1 clk for SENSI-BUS if (P1IN /(DATA) read bit Clear_CLK(); /SCK=0 DATA_OutDIR(); if(ack) Clear_DATA() ; else Set_DATA(); / DATA=!ack; in case of “ack=1“ pull down DATA-Line Set_CLK(); /SCK=1 clk #9 for ack _nop_();_nop_();_nop_(); /pulswith approx. 5 us Clear_CLK(); /SCK=0 Set_DATA(); /DATA=1 release DATA-line DATA_InDIR(); return val; /- void s_transstart(void) /- / generates a transmission start / _ _ / DATA: |_| / _ _ / SCK : _| |_| |_ DATA_OutDIR(); Set_DATA(); Clear_CLK(); /DATA=1 SCK=0 Initial state _nop_(); Set_CLK(); /SCK=1 _nop_(); Clear_DATA(); /DATA=0 _nop_(); Clear_CLK(); /SCK=0 _nop_();_nop_();_nop_(); Set_CLK(); /SCK=1 _nop_(); Set_DATA(); /DATA=1 _nop_(); Clear_CLK(); /SCK=0 DATA_InDIR(); /- void s_connectionreset(void) /- / communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart / _ _ / DATA: |_| / _ _ _ _ _ _ _ _ _ _ _ / SCK : _| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_ unsigned char i; DATA_OutDIR(); Set_DATA(); Clear_CLK(); /DATA=1 SCK=0 Initial state for(i=0;i=1 in case of no response form the sensor /- char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode) /- / makes a measurement (humidity/temperature) with checksum unsigned error=0; unsigned int i; s_transstart(); /transmission start switch(mode) /send command to sensor case TEMP: error+=s_write_byte(MEASURE_TEMP); break; case HUMI: error+=s_write_byte(MEASURE_HUMI); break; default : break; DATA_InDIR(); for (i=0;i100)rh_true=100; /cut if the value is outside of if(rh_true0.1)rh_true=0.1; /the physical possible range *p_temperature=t_C; /return temperature 癈 *p_humidity=r

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论