c语言温度湿度编程,温度湿度c语言代码

41528d3028836879cd698677c3999917.gif温度湿度c语言代码

#ifndef __TOU_H__//如果没有被编译过 #define __TOU_H__//那么标记为编译过 #include #include #include #include #define uint unsigned int #define uchar unsigned char enum {TEMP,HUMI}; sbit DATA = P2^5;//温湿度传感器位定义 sbit SCK = P2^4; void s_connectionreset(void);/******** SHT11函数声明 ********/ char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode); void calc_sth10(float *p_humidity ,float *p_temperature); float calc_dewpoint(float h,float t); #endif//结束#ifndef,如果已经编译过就跳过之间的部分 uchar code table1[]=“00:00:00“; uchar code table2[]=“00:00:00RH:00.0“; sbit shui1=P1^0; sbit shui2=P1^1; sbit shi_s1=P1^2; sbit shi_s2=P1^3; sbit shi_s3=P1^4; sbit led=P1^6; sbit sound=P1^7; sbit lcden=P2^2; sbit lcdrw=P2^1; sbit lcdrs=P2^0; sbit relay=P2^3; sbit s1=P2^7; uchar data disdata[4]; uchar num,count,s1num; char shi,fen,miao,shi1,fen1,miao1; uint bian,i,j; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } //SHT11程序(SHT11.c): #define noACK 0//继续传输数据,用于判断是否结束通讯 #define ACK 1 //结束数据传输; //地址 命令 读/写 #define STATUS_REG_W 0 x06 //000 0011 0 #define STATUS_REG_R 0 x07 //000 0011 1 #define MEASURE_TEMP 0 x03 //000 0001 1 #define MEASURE_HUMI 0 x05 //000 0010 1 #define RESET 0 x1e //000 1111 0 //写字节程序 char s_write_byte(unsigned char value) { unsigned char i,error=0; for (i=0 x80;i>0;i>>=1) //高位为1,循环右移 { if (i //和要发送的数相与,结果为发送的位 else DATA=0; SCK=1; _nop_();_nop_();_nop_(); //延时3us SCK=0; } DATA=1; //释放数据线 SCK=1; error=DATA; //检查应答信号,确认通讯正常 _nop_();_nop_();_nop_(); SCK=0; DATA=1; return error; //error=1 通讯错误 } //读字节程序 char s_read_byte(unsigned char ack) { unsigned char i,val=0; DATA=1; //释放数据线 for(i=0 x80;i>0;i>>=1) //高位为1,循环右移 { SCK=1; if(DATA) val=(val|i); //读一位数据线的值 SCK=0; } DATA=!ack; //如果是校验,读取完后结束通讯; SCK=1; _nop_();_nop_();_nop_(); //延时3us SCK=0; _nop_();_nop_();_nop_(); DATA=1; //释放数据线 return val; } //启动传输 void s_transstart(void) { DATA=1; SCK=0; _nop_(); SCK=1; _nop_(); DATA=0; _nop_(); SCK=0; _nop_();_nop_();_nop_(); SCK=1; _nop_(); DATA=1; _nop_(); SCK=0; } void s_connectionreset(void) { unsigned char i; DATA=1; SCK=0; //准备 for(i=0;i<9;i++) //DATA保持高,SCK时钟触发9次,发送启动传输,通迅即复位 { SCK=1; SCK=0; } s_transstart(); //启动传输 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值