📄 sht10.lst
字号:
C51 COMPILER V8.15 SHT10 08/06/2009 13:49:09 PAGE 1
C51 COMPILER V8.15, COMPILATION OF MODULE SHT10
OBJECT MODULE PLACED IN SHT10.OBJ
COMPILER INVOKED BY: D:\专业软件SLF\keil\C51\BIN\C51.EXE SHT10.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "reg52.h"
2 #include "intrins.h" //Keil library (is used for _nop()_ operation)
3 #include "math.h" //Keil library
4 #include "stdio.h"
5 #include "LED.h"
6 #include "44KEY.h"
7
8 #define uchar unsigned char
9 #define uint unsigned int
10
11 sbit DATA = P3^6; //定义通讯数据端口
12 sbit SCK = P3^7;
13
14 typedef union
15 { unsigned int i; //定义了两个共用体
16 float f;
17 } value;
18
19 enum {TEMP,HUMI}; //TEMP=0,HUMI=1
20
21 uint tempvalue,tempvalue2;
22 uint flag;
23 float wenduf,shiduf;
24 unsigned int wendu,shidu;
25
26 #define noACK 0 //用于判断是否结束通讯
27 #define ACK 1 //结束数据传输
28 //adr command r/w
29 #define STATUS_REG_W 0x06 //000 0011 0
30 #define STATUS_REG_R 0x07 //000 0011 1
31 #define MEASURE_TEMP 0x03 //000 0001 1
32 #define MEASURE_HUMI 0x05 //000 0010 1
33 #define RESET 0x1e //000 1111 0
34
35 /****************定义函数****************/
36 void s_transstart(void); //启动传输函数
37 void s_connectionreset(void); //连接复位函数
38 char s_write_byte(unsigned char value);//DHT90写函数
39 char s_read_byte(unsigned char ack); //DHT90读函数
40 char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode);//测量温湿
41 void calc_dht90(float *p_humidity ,float *p_temperature);//温湿度补偿
42 void delay_n10us(uint n); //延时函数
43
44 static void mDelay(unsigned int j)
45 {
46 1 uint i;
47 1 for(;j>0;j--)
48 1 {
49 2 for(i=124;i>0;i--)
50 2 {;}
51 2 }
52 1 }
53
54 /*--------------------------------------
55 ;模块名称:delay_n10us();
C51 COMPILER V8.15 SHT10 08/06/2009 13:49:09 PAGE 2
56 ;功 能:延时函数,延时约n个10us
57 ;占用资源:--
58 ;参数说明:--
59 ;创建日期:2008.08.15
60 ;版 本:FV1.1(函数版本Function Version)
61 ;修改日期:2008.08.26
62 ;修改说明:修改为较精确的延时函数,"_nop_()"延时1us@12M晶振
63 ;-------------------------------------*/
64 void delay_n10us(uint n) //延时n个10us@12M晶振
65 {
66 1 uint i;
67 1 for(i=n;i>0;i--)
68 1 {
69 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
70 2 }
71 1 }
72
73 /*--------------------------------------
74 ;模块名称:s_transstart();
75 ;功 能:启动传输函数
76 ;占用资源:--
77 ;参数说明:--
78 ;创建日期:2008.08.15
79 ;版 本:FV1.0(函数版本Function Version)
80 ;修改日期:--
81 ;修改说明:--
82 ;-------------------------------------*/
83 void s_transstart(void)
84 // generates a transmission start
85 // _____ ________
86 // DATA: |_______|
87 // ___ ___
88 // SCK : ___| |___| |______
89 {
90 1 DATA=1; SCK=0; //Initial state
91 1 _nop_();
92 1 SCK=1;
93 1 _nop_();
94 1 DATA=0;
95 1 _nop_();
96 1 SCK=0;
97 1 _nop_();_nop_();_nop_();
98 1 SCK=1;
99 1 _nop_();
100 1 DATA=1;
101 1 _nop_();
102 1 SCK=0;
103 1 }
104
105 /*--------------------------------------
106 ;模块名称:s_connectionreset();
107 ;功 能:连接复位函数
108 ;占用资源:--
109 ;参数说明:--
110 ;创建日期:2008.08.15
111 ;版 本:FV1.0(函数版本Function Version)
112 ;修改日期:--
113 ;修改说明:--
114 ;-------------------------------------*/
115 void s_connectionreset(void)
116 // communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart
117 // _____________________________________________________ ________
C51 COMPILER V8.15 SHT10 08/06/2009 13:49:09 PAGE 3
118 // DATA: |_______|
119 // _ _ _ _ _ _ _ _ _ ___ ___
120 // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
121 {
122 1 unsigned char i;
123 1 DATA=1; SCK=0; //Initial state
124 1 for(i=0;i<9;i++) //9 SCK cycles
125 1 {
126 2 SCK=1;
127 2 SCK=0;
128 2 }
129 1 s_transstart(); //transmission start
130 1 }
131
132 /*--------------------------------------
133 ;模块名称:s_write_byte();
134 ;功 能:DHT90写函数
135 ;占用资源:--
136 ;参数说明:--
137 ;创建日期:2008.08.15
138 ;版 本:FV1.0(函数版本Function Version)
139 ;修改日期:--
140 ;修改说明:--
141 ;-------------------------------------*/
142 char s_write_byte(unsigned char value)
143 //----------------------------------------------------------------------------------
144 // writes a byte on the Sensibus and checks the acknowledge
145 {
146 1 unsigned char i,error=0;
147 1 for (i=0x80;i>0;i/=2) //shift bit for masking
148 1 {
149 2 if (i & value) DATA=1; //masking value with i , write to SENSI-BUS
150 2 else DATA=0;
151 2 SCK=1; //clk for SENSI-BUS
152 2 _nop_();_nop_();_nop_(); //pulswith approx. 3 us
153 2 SCK=0;
154 2 }
155 1 DATA=1; //release DATA-line
156 1 SCK=1; //clk #9 for ack
157 1 error=DATA; //check ack (DATA will be pulled down by DHT90),DATA在第9个
158 1
159 1
160 1 _nop_();_nop_();_nop_();
161 1 SCK=0;
162 1 DATA=1; //release DATA-line
163 1 return error; //error=1 in case of no acknowledge //返回:0成功,1失败
164 1 }
165
166
167 /*--------------------------------------
168 ;模块名称:s_read_byte();
169 ;功 能:DHT90读函数
170 ;占用资源:--
171 ;参数说明:--
172 ;创建日期:2008.08.15
173 ;版 本:FV1.0(函数版本Function Version)
174 ;修改日期:--
175 ;修改说明:--
176 ;-------------------------------------*/
177 char s_read_byte(unsigned char ack)
178 // reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
179 {
C51 COMPILER V8.15 SHT10 08/06/2009 13:49:09 PAGE 4
180 1 unsigned char i,val=0;
181 1 DATA=1; //release DATA-line
182 1 for (i=0x80;i>0;i/=2) //shift bit for masking
183 1 { SCK=1; //clk for SENSI-BUS
184 2 if (DATA) val=(val | i); //read bit
185 2 _nop_();_nop_();_nop_(); //pulswith approx. 3 us
186 2 SCK=0;
187 2 }
188 1 if(ack==1)DATA=0; //in case of "ack==1" pull down DATA-Line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -