📄 sht11.lst
字号:
C51 COMPILER V8.12 SHT11 07/05/2008 15:30:15 PAGE 1
C51 COMPILER V8.12, COMPILATION OF MODULE SHT11
OBJECT MODULE PLACED IN SHT11.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SHT11.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" /*Keil library*/
5 #include "absacc.h"
6 #include "12864s.h"
7
8 #define ACK 1
9 #define noACK 0
10 #define measure_temp 0x03 //测量温度命令
11 #define measure_humi 0x05 //测量湿度命令
12 #define RESET 0x1e //软启动
13
14 #define uchar unsigned char
15 #define uint unsigned int
16 #define ulong unsigned long
17
18
19 sbit DATA=P1^0;
20 sbit SCK=P1^1;
21
22 typedef union /*保存所测得的温度&湿度值*/
23 { uint i;
24 float f;
25 } value;
26
27 typedef struct __SYSTEMTIME__
28 {
29 unsigned char gewei;
30 unsigned char shiwei;
31 unsigned char DateString1[5];
32 unsigned char DateString2[6];
33 }SYSTEMTIME;
34
35 char write_byte(unsigned char value)
36 // writes a byte on the Sensibus and checks the acknowledge
37 {
38 1 unsigned char i,error=0;
39 1 for (i=0x80;i>0;i/=2) /*连续向右移动8位*/
40 1 {
41 2 if (i & value) DATA=1; /*把相应的位送数据线*/
42 2 else DATA=0;
43 2 SCK=1; /*时序脉冲,应严格按着此标准*/
44 2 _nop_();
45 2 _nop_();
46 2 _nop_(); /*大约0.5us*/
47 2 SCK=0;
48 2 }
49 1 DATA=1; /*释放数据线*/
50 1 SCK=1; /*第9位作为响应位*/
51 1 error=DATA; /*检测响应情况,如果有响应数据线就会被SHT10拉低*/
52 1 SCK=0;
53 1 return error; /*返回1表示没响应*/
54 1 }
55
C51 COMPILER V8.12 SHT11 07/05/2008 15:30:15 PAGE 2
56 char read_byte(unsigned char ack)
57 {
58 1 unsigned char i,val=0;
59 1 DATA=1; /*释放数据线*/
60 1 for (i=0x80;i>0;i/=2) /*连续向右移动8位*/
61 1 { SCK=1; /*clk for SENSI-BUS*/
62 2 if (DATA) val=(val | i); /*read bit */
63 2 SCK=0;
64 2 }
65 1 DATA=!ack; /*当ack=1时拉低数据线*/
66 1 SCK=1; /*clk #9 for ack*/
67 1 _nop_();_nop_();_nop_(); /*pulswith approx. 5 us */
68 1 SCK=0;
69 1 DATA=1; /*释放数据线*/
70 1 return val;
71 1 }
72
73 void transstart(void)
74 {
75 1 DATA=1;
76 1 SCK=0; //初始状态
77 1 _nop_();
78 1 SCK=1;
79 1 _nop_();
80 1 DATA=0;
81 1 _nop_();
82 1 SCK=0;
83 1 _nop_();_nop_();_nop_();
84 1 SCK=1;
85 1 _nop_();
86 1 DATA=1;
87 1 _nop_();
88 1 SCK=0;
89 1 }
90
91 void connectionreset(void)//复位:当DATA线处于高低平时,触发SCK9次以上(含9次),此后应接发一个"传输开始"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -