下载此文档

温度湿度c语言代码.docx


文档分类:高等教育 | 页数:约14页 举报非法文档有奖
1/14
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/14 下载此文档
文档列表 文档介绍
#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:";
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程序():
#define noACK 0 //继续传输数据,用于判断是否结束通讯
#define ACK 1 //结束数据传输;
//地址 命令 读/写
#define STATUS_REG_W 0x06 //000 0011 0
#define STATUS_REG_R 0x07 //000 0011 1
#define MEASURE_TEMP 0x03 //000 0001 1
#define MEASURE_HUMI 0x05 //000 0010 1
#define RESET 0x1e //000 1111 0
//写字节程序
char s_write_byte(unsigned char value)
{
unsigned char i,error=0;
for (i=0x80;i>0;i>>=1) //高位为1,循环右移
{
if (i&value) DATA=1; //和要发送的数相与,结果为发送的位
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

温度湿度c语言代码 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数14
  • 收藏数0 收藏
  • 顶次数0
  • 上传人bai1968104
  • 文件大小79 KB
  • 时间2021-08-04