传感器课设——温湿度传感器sht10监控系统(温湿度采集、液晶1602显示、键盘控制、声光报警)程序

合集下载

SHT10(温湿度传感器)

SHT10(温湿度传感器)

字输出转换为温度值:
Temperature = d1 + d2 •SOT
8 bit
-4
0.648 -7.2 * 10-4
表6
湿度转换系数
简化的修正算法,可参阅应用说明“相对 湿度与温度的非线性补偿”。
对高于 99%RH 的那些测量值则表示空气 已经完全饱和,必须被处理成显示值均为 100%2RH。湿度传感器对电压基本上没有依赖 性。
3.2 温度
由能隙材料 PTAT (正比于绝对温度) 研发的 温度传感器具有极好的线性。可用如下公式将数
图9
时序 图
1) 试样参数周期性抽检但非 100% 检测 (2) 由于传感器在 3.3V 校准,对于要求最高精度测量推荐采用 2.4-3.6V 供电 (3) 每秒进行一次 8bit 精度的测量,不加载 OTP
(4) 每秒进行一次 12bit 精度的测量

V3.01 2007.08
图 7 状态寄存器写
图 8 状态寄存器读
Bit 类型 说明
7
预留
6R
电量不足 (低电压检测) ‘0’对应 Vdd > 2.47 ‘1’对应 Vdd < 2.47
5
预留
4
预留
3
仅供测试, 不使用
2 R/W 加热
1 R/W 不从 OTP 加载
0 R/W ‘1’= 8bit RH / 12bit T 分辨率
原始数据 线性化
±3
%RH
<<1
%RH
0
100 %RH
响应时间
1/e (63%)
68
10
S
25℃ ,1m/s 空气
迟滞
±1
%RH

温湿度传感器SHT10驱动程序

温湿度传感器SHT10驱动程序

温湿度传感器SHT10驱动程序——基于MSP430这是暑假时用430的单片机写的温湿度传感器SHT10的程序,参考了官方的51例程,分享一下~~/****************************************Copyright(c)********************************************************************************************LiPeng********************* *************************************--------------FileInfo-------------------------------------------------------------------------------** File Name: Sht10_Driver.c** Created by: LiPeng** Created date: 2008-09-15** Version: 1.0** Descriptions: The original version****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Descriptions:****------------------------------------------------------------------------------------------------------** System Function: Sht10 Driver------温湿度传感器SHT10驱动** 使用MSP430-F413连接方式:** VCC: P6.3** SCK: P6.4** SDA: P6.5*********************************************************************** ***********************************/#include <msp430x14x.h>/*宏定义,延时函数,参数为1时相应延时分别为1us和1ms*/#define CPU_F (double)1000000#define delay_us(x) __delay_cycles((long)(CPU_F * (double)x/1000000.0)) #define delay_ms(x) __delay_cycles((long)(CPU_F * (double)x/1000.0))/*常量定义*/#define uint unsigned int#define uchar unsigned char#define ulong unsigned long//adr command r/w#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#define bitselect 0x01 //选择温度与湿度的低位读#define noACK 0#define ACK 1#define HUMIDITY 2#define TEMPERATURE 1#define SCK BIT4#define SDA BIT5#define SVCC BIT3#define SCK_H P6OUT|=SCK#define SCK_L P6OUT&=~SCK#define SDA_H P6OUT|=SDA#define SDA_L P6OUT&=~SDA#define SVCC_H P6OUT|=SVCC#define SVCC_L P6OUT&=~SVCCtypedef union{unsigned int i;float f;}value;uint table_temp[3];uint table_humi[3];uint temten;uint humi_true;/******************************************************************** ****************************************Function Name: S_Init**Description: 初始化**Input Parameters: 无**Output Parameters: 无*************************************/void S_Init(){P6SEL&=~(SCK+SDA+SVCC); //选择P6.3 P6.4 为IO端口,输出 P6.5输入P6DIR|=(SCK+SVCC);P6DIR&=~SDA;BCSCTL1=(XT2OFF+RSEL2); //关闭XT2,1MHz DOCDCOCTL=DCO2; //设定DCO频率为1MHz}/******************************************************************** ****************************************Function Name: S_Transstart**Description: 发送开始时序**** generates a transmission start** _____ ________** DATA: |_______|** ___ ___** SCK : ___| |___| |______**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/void S_Transstart(){P6DIR|=SDA;SDA_H;SCK_L;_NOP();SCK_H;_NOP();SDA_L;_NOP();SCK_L;_NOP();_NOP();_NOP();SCK_H;_NOP();SDA_H;_NOP();SCK_L;P6DIR&=~SDA;}****************************************Function Name: S_WriteByte**Description: 写时序**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/char S_WriteByte(unsigned char value){unsigned char i,error=0;P6DIR|=SDA;for(i=0x80;i>0;i/=2) //shift bit for masking{if(i&value)SDA_H; //masking value with i , write to SENSI-BUSelseSDA_L;SCK_H; //clk for SENSI-BUS_NOP();_NOP();_NOP(); //pulswith approx. 5 usSCK_L;}SDA_H; //release DATA-lineP6DIR&=~SDA; //Change SDA to be inputSCK_H; //clk #9 for ackerror=P6IN; //check ack (DATA will be pulled down by SHT11)error&=SDA;P6DIR|=SDA;SCK_L;if(error)return 1; //error=1 in case of no acknowledgereturn 0;}/******************************************************************** ****************************************Function Name: S_ReadByte**Description: 读时序**Input Parameters: ack--->reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"**Output Parameters: 无********************************************************************* *************************************/char S_ReadByte(unsigned char ack){unsigned char i,val=0;P6DIR|=SDA;SDA_H; //release DATA-lineP6DIR&=~SDA;for(i=0x80;i>0;i/=2) //shift bit for masking{SCK_H; //clk for SENSI-BUSif(P6IN&SDA)val=(val|i); //read bitSCK_L;}P6DIR|=SDA;if(ack) //in case of "ack==1" pull down DATA-LineSDA_L;elseSDA_H;SCK_H; //clk #9 for ack_NOP();_NOP();_NOP(); //pulswith approx. 5 usSCK_L;SDA_H; //release DATA-lineP6DIR&=~SDA;return val;}/******************************************************************** ****************************************Function Name: S_Connectionreset**Description: 通讯复位时序** communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart** _____________________________________________________ ________** DATA: |_______|** _ _ _ _ _ _ _ _ _ ___ ___** SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ **Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/void S_Connectionreset(){unsigned char ClkCnt;P6DIR|=SDA;SDA_H;SCK_L; //Initial statefor(ClkCnt=0;ClkCnt<9;ClkCnt++) //9 SCK cycles{SCK_H;SCK_L;}S_Transstart(); //transmission start}/******************************************************************** ****************************************Function Name: S_Softreset**Description: 软件复位时序resets the sensor by a softreset**Input Parameters: 无**Output Parameters: 无********************************************************************* *************************************/char S_Softreset(){unsigned char error=0;S_Connectionreset(); //reset communicationerror+=S_WriteByte(RESET); //send RESET-command to sensorreturn error; //error=1 in case of no response form the sensor}/******************************************************************** ****************************************Function Name: S_WriteStatusReg**Description: 写状态寄存器**Input Parameters: *p_value**Output Parameters: 无********************************************************************* *************************************/char S_WriteStatusReg(unsigned char *p_value){unsigned char error=0;S_Transstart(); //transmission starterror+=S_WriteByte(STATUS_REG_W); //send command to sensorerror+=S_WriteByte(*p_value); //send value of status registerreturn error; //error>=1 in case of no response form the sensor}/******************************************************************** ****************************************Function Name: S_Mearsure**Description: 读时序 makes a measurement (humidity/temperature) withchecksum**Input Parameters: *p_value ,*p_checknum ,mode**Output Parameters: 无********************************************************************* *************************************/unsigned char S_Measure(unsigned char *p_value, unsigned char*p_checksum, unsigned char mode){unsigned error=0;unsigned int i;S_Transstart(); //transmission startswitch(mode){ //send command to sensorcase TEMPERATURE: error+=S_WriteByte(MEASURE_TEMP); break;case HUMIDITY: error+=S_WriteByte(MEASURE_HUMI); break;}P6DIR&=~SDA;for(i=0;i<65535;i++) //wait until sensor has finished the measurement if((P6IN&SDA)==0)break;if(P6IN&SDA)error+=1; //or timeout (~2 sec.) is reached*(p_value)=S_ReadByte(ACK); //read the first byte (MSB)*(p_value+1)=S_ReadByte(ACK); //read the second byte (LSB)*p_checksum=S_ReadByte(noACK); //read checksumreturn(error);}/******************************************************************** ****************************************Function Name: S_Calculate**Description: 计算**Input Parameters: humi [Ticks] (12 bit)** temp [Ticks] (14 bit)**Output Parameters: humi [%RH]** temp [癈]********************************************************************* *************************************/void S_Calculate(unsigned int *p_humidity ,unsigned int *p_temperature) {const float C1=-4.0; // for 8 Bitconst float C2=+0.648; // for 8 Bitconst float C3=-0.0000072; // for 8 Bitconst float D1=-39.6; // for 12 Bit @ 3Vconst float D2=+0.04; // for 12 Bit @ 3Vconst float T1=0.01; // for 8 bitconst float T2=0.00128; // for 8 bitfloat rh=*p_humidity; // rh: Humidity [Ticks] 12 Bitfloat t=*p_temperature; // t: Temperature [Ticks] 14 Bitfloat rh_lin; // rh_lin: Humidity linearfloat rh_true; // rh_true: Temperature compensated humidityfloat t_C; // t_C : Temperature [癈]t_C=t*D2+D1; //calc. temperature from ticks to [癈]rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]if(rh_true>100)rh_true=100; //cut if the value is outside ofif(rh_true<0.1)rh_true=0.1; //the physical possible range*p_temperature=t_C; //return temperature [癈]*p_humidity=rh_true; //return humidity[%RH]}void main(){value humi_val,temp_val;unsigned char error,checksum;unsigned int i,temphigh,templow;unsigned int RegCMD=0x01;WDTCTL=WDTPW+WDTHOLD; //Stop watchdog timer to prevent time out resetS_Init();SVCC_H;S_Connectionreset();S_WriteStatusReg((unsigned char *)&RegCMD);while(1){error=0;error+=S_Measure((unsigned char*) &humi_val.i,&checksum,HUMIDITY);//measure humidityerror+=S_Measure((unsigned char*) &temp_val.i,&checksum,TEMPERATURE); //measure temperatureif(error!=0)S_Connectionreset(); //in case of an error: connection resetelse{templow=(humi_val.i&0xff00);humi_val.i=templow>>8;temphigh=((temp_val.i&0xf)<<8);templow=((temp_val.i&0xff00)>>8);temp_val.i=temphigh+templow;S_Calculate(&humi_val.i,&temp_val.i); //calculate humidity, temperature//temp_val_NOP();//printf("temp:%5.1fC humi:%5.1f%% dewpoint:%5.1fC\n",temp_val.f,humi_val.f,dew_point);}//----------wait approx. 0.8s to avoid heating upSHTxx------------------------------for (i=0;i<40000;i++); //(be sure that the compiler doesn't eliminate this line!)//-----------------------------------------------------------------------------------}}。

实验一 温湿度传感器

实验一 温湿度传感器

图 1-1-6 传感器件位置
(8) 测试完成后, 按下 Sensors 键蓝色按钮, 即关闭传感器板卡电源。 此时传感器断电, 在母板的显示屏上显示“请给传感器模块上电! ” ;再次按下蓝色按钮,即关闭单片机电源。 二. 完成程序并重新烧写程序,并观察显示效果
(1)利用 keil2 软件,打开目录“D:\传感器实验箱资料\传感器实验箱程序资料\C51\ 完成部分程序\完成部分程序”中的 SHT10.Uv2 文件。 (2) 双击打开左侧的“wenshi.c”文件,根据提示完成部分程序。
图 1-1-3 仿真器
3. 烧写程序并观察效果 (1) 切换频率, 把母版右侧上红色的 1、2 按钮都拨到 ON 的位置。 (2) 打开母版电源:即把黑色按钮向上拨动,如图 1-1-4 所示。
图 1-1-4 母板电源开关
(3) 当 (2)中的电源打开时, 观察母板上的显示屏幕中显示的内容。 其显示的内容为 “请 给传感器模块上电! ” 。 (4) 打开 D:\传感器实验箱资料\实验箱系统软件及驱动\STC 手动下载\STC-ISP.exe 烧 写软件,进行烧写,步骤如下。 1 选择 MCU TYPE:STC12LE5A60S2; ○ 2 打开文件: ○ 选择 D:\传感器实验箱资料\传感器实验箱程序资料\C51\SHT10_温湿度传
表 1-1-4 相对湿度的温度补偿转换系数 SORH 12 位 8位 t1 0.01 0.01 t2 0.00008 0.00128
2. 温度 温度计算公式如下所示。
T = d1 + d 2 *SO T
温度转换系数 d1 如下表所示。
表 1-1-5 温度转换系数 d1 VDD 5V 4V 3.5V 3V 2.5V d1(C) -40.1 -39.8 -39.7 -39.6 -39.4 d1(F) -40.2 -39.6 -39.5 -39.3 -38.9

SHT10空气温湿度MODbus协议(单指令)

SHT10空气温湿度MODbus协议(单指令)

SHT10温湿度传感器的通信协议命令包含:1.读取站号命令2.写站号命令3.读取数据4.手动矫正数据串口参数设置:读站号命令(固定命令)主站从站地址功能码H地址L地址 H数据L数据 CRC00 03 00 01 00 01 CRClo CRChi 从站从站地址功能码H地址L地址H数据CRC00 03 02 00 XX CRClo CRChi 注:返回帧与主站相同设备地址:(XX=01-FF)示例:命令00 03 00 01 00 01 D4 1B(固定命令)回复00 03 02 00 FF C5 C4 (设备默认站号FF)写站号命令主站从站地址功能码H地址L地址寄存器个数寄存器个数数据长度数据CRC00 10 00 01 00 01 02 00 XX CRClo CRChi 注:(XX=0X01-0XFF)从站从站地址功能码 H地址L地址寄存器个数CRC00 10 00 01 00 01 CRClo CRChi 示例:命令00 10 00 01 00 01 02 00 33 EA 04回复00 10 00 01 00 01 51 D8读数据主站从站地址功能码 H地址L地址寄存器个数寄存器个数CRCXX 03 00 00 00 02 CRClo CRChi注:(XX=0X01-0XFF)从站从站地址功能码数据长度数据数据CRCXX 03 04 19 AD 1B E4 CRClo CRCh 示例命令FF 03 00 00 00 02 D1 D5回复FF 03 04 19 AD 1B E4 79 FA注:温度:第4,5个字节19 AD温度=读数/100-40度湿度:第5,6个字节1B E4。

大棚温湿度自动控制系统设计 毕业设计

大棚温湿度自动控制系统设计 毕业设计

大棚温湿度自动控制系统设计摘要:本设计是基于STC89C52RC单片机的大棚温湿度自动控制系统,采用SHT10作为温湿度传感器,LCD1602液晶屏进行显示。

SHT10使用类似于I2C总线的时序与单片机进行通信,由于它高度集成,已经包括A/D转换电路,所以使用方便,而且准确、耐用。

LCD1602能够分两行显示数据,第一行显示温度,第二行显示湿度。

这个控制系统能够测量温室大棚中的温度和湿度,将其显示在液晶屏LCD1602上,同时将其与设定值进行对比,如果超出上下限,将进行报警并启动温湿度调节设备。

此外,还可以通过独立式键盘对设定的温湿度进行修改。

通过设计系统原理图、用Proteus软件进行仿真,证明了该系统的可行性。

关键词:STC89C52RC,SHT10,I2C总线,独立式键盘,温湿度自动控制Abstract:This design is an automatic temperature and humidity controller for greenhouses,with the STC89C52RC MCU being its main controller. It uses the SHT10 as the temperature and humidity sensor,and the LCD1602 to display the messages。

The SHT10 uses a timing sequence much like the I2C to communicate with the micro—controller. Because it's a highly integrated chip, it already includes an analog to digital converter。

Therefore, it’s quite convenient to use, and also accurate and durable. The LCD1602 can display two lines of messages,with the first line for temperature and the second line for humidity。

SHT10,SHT11,SHT20,SHT21替代品温湿度传感器HTU21D

SHT10,SHT11,SHT20,SHT21替代品温湿度传感器HTU21D

最小值
-40
-40 -40
典型值
0.01 0.04
±0.3 ±0.4
44 22 11 6 10
最大值
+125
125 221 58 29 15
8
单位
℃ ℃ ℃
℃ ℃ ℃ °F ms ms ms ms s
9.温度误差估算
温湿度感应芯片HTU21D郑:18070430980
10.焊接说明 可以使用标准的回流焊炉对 HTU21 进行焊接。传感器完全符合 IPC/JEDEC J-STD-020D 焊
2.传感器的特点
·完整的互换性,在标准环境下无需校准 ·长期处于湿度饱和状态,可以迅速恢复 ·自动组装工艺生产,无铅材料制成,适合回流焊 ·每个传感器具有单独标记,可追溯生产源头
应用举例
·家庭应用 ·医疗领域 ·打印机 ·加湿器
3.性能规格
参数
储藏温度
供电电压(峰值)
湿度测量范围
温度测量范围
VDD to GND 数字 I/O 口引脚(DATA/SCK)to VDD 每个引脚输入电流
·相对湿度转换
不论基于哪种分辨率,相对湿度RH 都可以根据SDA 输出的相对湿度信号SRH通过如下 公式计算获得 (结果以 %RH 表示):
例如16位的湿度数据为0x6350:25424,相对湿度的计算结果为42.5%RH。
·温度转换
不论基于哪种分辨率,温度T 都可以通过将温度输出信号ST代入到下面的公式计算得到 (结果以温度°C 表示):
无论哪种传输模式,由于测量的最大分辨率为14 位,第二个字节SDA 上的后两位LSBs (bit43 和44)用来传输相关的状态信息。两个LSBs 中的bit1 表明测量的类型(’0’温度;‘1’: 湿度)。bit0 位当前没有赋值。

课程设计基于单片机的温湿度传感器

课程设计基于单片机的温湿度传感器

由于温度与湿度不管是从物理量本身还是在实际人们的生活中都有着密切的关系,所以温湿度一体的传感器就会相应产生。

DHT11与单片机之间能采用简单的单总线进行通信,仅仅需要一个I/O口。

操作简单,使用基亚5110二手屏幕显示DHT11传感器读出来的温度和湿度值。

关键字:AT89S52;5110液晶;DHT11传感器;单总线AbstractBecause of the temperature and the humidity from both the physical quantity itself or in the actual life of people are closely related, so the temperature and humidity sensor integrated will arise accordingly. Between DHT11 and SCM can adopt the simple single bus, only need a I\/O port. Simple operation, using the base of 5110 secondhand screen display DHT11 sensor Read out the temperature and humidity.Keywords: AT89S52; DHT11 5110 LCD; sensor; single bus引言 ------------------------------------------11.1 DHT11描述---------------------------------------------------21.2 管脚排列----------------------------------------------21.3 应用电路连接说明--------------------------------------21.4 DHT11数据结构-----------------------------------------31.5 DHT11的传输时序---------------------------------------31.5.1 DHT11开始发送数据流程--------------------------31.5.2 主机复位信号和DHT11响应信号 --------------------31.5.3 数字‘0’信号表示方法-----------------------------31.5.4 数字‘1’信号表示方法-----------------------------42、诺基亚5110液晶简介(PCD8544驱动)--------------------42.1 引脚---------------------------------------------------4 2.2 功能描述:---------------------------------------------52.2.1 地址计数器 (AC)--------------------------------52.2.2 初始化-------------------------------------------52.2.3复位的作用----------------------------------------62.2.4显示控制------------------------------------------62.2.5 串行接口时序--------------------------------------62.2.6 指令集 ------------------------------------------63、总结-------------------------------------------------74、谢辞-------------------------------------------------85、参考文献---------------------------------------------96、附录-------------------------------------------------105.1 实验总框架图---------------------------------------------10 5.2 硬件部分-------------------------------------------------105.2.1硬件原理图-------------------------------------------10 5.2.2 硬件PCB图-------------------------------------------11 5.2.3 所需元器件-------------------------------------------115.3 实验效果-------------------------------------------------11 5.4 实验软件程序---------------------------------------------12引言可靠性与卓越的长期稳定性。

温湿度传感器实验报告

温湿度传感器实验报告

小型智能系统设计------- 实验项目报告实验名称:基于STC 89C52单片机的温湿度变送器实验日期: 2014年5月——2014年6月院系:电子科学与工程学院专业:微电子科学与工程指导老师:张熠姓名:高波学号:B13020927EDA实验室开课时间:2013/2014 学年第二学期摘要随着人们生活水平的不断提高,利用单片机实现智能控制无疑是人们追求的目标之一,它给人带来的方便也是毋庸置疑的,其中温度传感器就是其中的一个典型例子,但是人们对单片机的控制要求越来越高。

要为现代人工作,生活,科研,学习提供更好、更方便、更人性化的设施就要从单片机技术入手,一切向数字化、智能控制化方向发展。

温湿度变送器基于STC 89C52 单片机,配以DHT11传感器、DS1302显示器以及RS485中继站,具有精度高、适用范围广、生产加工简单、成本低、支持远距离传送、操作简单等优点。

是工农业生产和日常生活都非常实用的一种器件。

目录序言 (3)第一章温度采集器总体设计方案 (4)1.0 温度采集器设计方案论述 (4)1.1 方案明细 (4)第二章硬件设计 (7)2.0 1-wire总线协议介绍 (7)2.1S T C89C52的简单介绍 (8)2.2D H T11特点及电气特性 (9)2.3 MAX232特点及电气特性 (10)2.4 11.0592晶体振荡器电气特性 (13)第三章系统软件设计 (13)3.0主程序设计 (13)3.1 温度程序设计(DHT11模块) (13)3.2 时间程序设计(DS1302模块) (14)第四章总结与体会 (14)第五章软件仿真与系统调试 (16)5.0 protues软件仿真 (19)5.1 keil version仿真 (25)5.2 实物照片 (29)第六章附录 (29)6.0 主程序源代码 (30)序言智能温度传感器智能温度传感器(亦称数字温度传感器)是在20世纪90年代中期问世的。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

温湿度监控C语言源程序#include <reg51.h>#include <intrins.h>#include <math.h> //Keil library#include <stdio.h> //Keil library/******************** LCD1602设置****************************************/#define LCD_DB P0sbit LCD_RS=P2^5;sbit LCD_RW=P2^6;sbit LCD_E=P2^7;/******定义函数****************/#define uchar unsigned char#define uint unsigned intvoid LCD_init(void); //初始化函数void LCD_write_command(uchar command); //写指令函数void LCD_write_data(uchar dat); //写数据函数void LCD_disp_char(uchar x,uchar y,uchar dat);//在某个屏幕位置上显示一个字符,X (0-15),y(1-2)void LCD_disp_str(uchar x,uchar y,uchar *str); //LCD1602显示字符串函数void delay_n10us(uint n); //延时函数/**************************************模块名称:LCD_init(); 功能:初始化LCD1602***************************************/void LCD_init(void){delay_n10us(10);LCD_write_command(0x38);//设置8位格式,2行,5x7delay_n10us(10);LCD_write_command(0x0c);//整体显示,关光标,不闪烁delay_n10us(10);LCD_write_command(0x06);//设定输入方式,增量不移位delay_n10us(10);LCD_write_command(0x01);//清除屏幕显示delay_n10us(100); //延时清屏,延时函数,延时约n个10us}/*****************************************模块名称:LCD_write_command();功能:LCD1602写指令函数******************************************/void LCD_write_command(uchar dat){delay_n10us(10);LCD_RS=0; //指令LCD_RW=0; //写入LCD_E=1; //允许LCD_DB=dat;delay_n10us(10); // 用for循环1次就能完成普通写指令。

LCD_E=0;delay_n10us(10); // 用for循环1次就能完成普通写指令。

}/****************************************模块名称:LCD_write_data();功能:LCD1602写数据函数******************************************/void LCD_write_data(uchar dat){delay_n10us(10);LCD_RS=1; //数据LCD_RW=0; //写入LCD_E=1; //允许LCD_DB=dat;delay_n10us(10);LCD_E=0;delay_n10us(10);}/*******************************************************模块名称:LCD_disp_char();功能:LCD1602显示一个字符函数,在某个屏幕位置上显示一个字符,X(0-15),y(1-2)。

*********************************************************/void LCD_disp_char(uchar x,uchar y,uchar dat){uchar address;if(y==1)address=0x80+x;elseaddress=0xc0+x;LCD_write_command(address);LCD_write_data(dat);}/***************************************************模块名称:LCD_disp_str();功能:LCD1602显示字符串函数,在某个屏幕起始位置{X(0-15),y(1-2)}上显示字符串。

***************************************************/void LCD_disp_str(uchar x,uchar y,uchar *str){ uchar address;if(y==1) address=0x80+x;elseaddress=0xc0+x; LCD_write_command(address);while(*str!='\0'){ LCD_write_data(*str); str++; } }/****************************************模块名称:delay_n10us();功能:延时函数,延时约n个10us*****************************************/void delay_n10us(uint n) //延时n个10us-12M晶振{uint i;for(i=n;i>0;i--){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}}/***************SHT10设置****************************************/sbit DA TA = P3^0; //定义通讯数据端口sbit SCK = P3^1; //定义通讯时钟端口typedef union{ unsigned int i; //定义了两个共用体float f;} value;enum {TEMP,HUMI}; //TEMP=0,HUMI=1#define noACK 0 //用于判断是否结束通讯#define ACK 1 //结束数据传输//adr command r/w#define STA TUS_REG_W 0x06 //000 0011 0#define STA TUS_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/****************定义函数****************/void s_transstart(void); //启动传输函数void s_connectionreset(void); //连接复位函数char s_write_byte(unsigned char value);//SHT10写函数char s_read_byte(unsigned char ack); //SHT10读函数char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode); //测量温湿度函数void calc_sht10(float *p_humidity ,float *p_temperature);//温湿度补偿/************************************************模块名称:s_transstart();功能:启动传输函数*************************************************/void s_transstart(void)// generates a transmission start// _____ ________// DA TA: |_______|// ___ ___// SCK : ___| |___| |______{DA TA=1; SCK=0; //Initial state_nop_(); SCK=1; _nop_(); DA TA=0; _nop_(); SCK=0; _nop_();_nop_();_nop_();SCK=1; _nop_(); DA TA=1; _nop_(); SCK=0;}/**********************************************模块名称:s_connectionreset(); 功能:连接复位函数************************************************/void s_connectionreset(void)// communication reset: DA TA-line=1 and at least 9 SCK cycles followed by transstart// _____________________________________________________ ________ // DA TA: |_______|// _ _ _ _ _ _ _ _ _ ___ ___// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______{unsigned char i;DA TA=1; SCK=0; //Initial statefor(i=0;i<9;i++) //9 SCK cycles{SCK=1;SCK=0;}s_transstart(); //transmission start}/**********************************************模块名称: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) DA TA=1; //masking value with i , write to SENSI-BUSelse DA TA=0;SCK=1; //clk for SENSI-BUS_nop_();_nop_();_nop_(); //pulswith approx. 3 usSCK=0;}DA TA=1; //release DA TA-lineSCK=1; //clk #9 for ackerror=DA TA; //DA TA在第9个上升沿将被SHT10下拉为低电平。

相关文档
最新文档