⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sht11.lst

📁 基于单片机AT89C52的温湿度传感器显示程序
💻 LST
字号:
C51 COMPILER V8.05a   SHT11                                                                08/06/2008 10:52:27 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE SHT11
OBJECT MODULE PLACED IN SHT11.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil 51\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          
   7          #define ACK 1
   8          #define noACK 0
   9          #define measure_temp 0x03 //测量温度命令 
  10          #define measure_humi 0x05 //测量湿度命令 
  11          #define RESET        0x1e //软启动 
  12          
  13          #define     uchar    unsigned   char
  14          #define     uint     unsigned   int
  15          #define     ulong    unsigned   long
  16          #define     LCD_DATA P0 //数据口  
  17          
  18          sbit   DATA=P1^0;
  19          sbit   SCK=P1^1;
  20          sbit   RS = P2^0; //并行的指令/数据选择信号, H数据, L命令
  21          sbit   RW = P2^1; //并行读写选择信号, H读, L写
  22          sbit   E =  P2^2;  //并行使能端, H有效, L无效
  23          sbit   LED=P3^7; 
  24          
  25          typedef union                      /*保存所测得的温度&湿度值*/
  26          { uint  i;
  27            float f;
  28          } value;
  29          
  30          typedef struct __SYSTEMTIME__
  31          {
  32                  unsigned char gewei;
  33                  unsigned char shiwei;
  34                  unsigned char DateString1[5];
  35              unsigned char DateString2[6];
  36          }SYSTEMTIME;
  37          
  38          char write_byte(unsigned char value)
  39          // writes a byte on the Sensibus and checks the acknowledge 
  40          { 
  41   1        unsigned char i,error=0;  
  42   1        for(i=0x80;i>0;i/=2)             /*连续向右移动8位*/
  43   1        { 
  44   2          if (i & value) DATA=1;          /*把相应的位送数据线 */
  45   2          else DATA=0;                        
  46   2          SCK=1;                          /*时序脉冲,应严格按着此标准 */
  47   2          _nop_();
  48   2          _nop_();
  49   2          _nop_();                        /*大约0.5us*/       
  50   2          SCK=0;
  51   2        }
  52   1        DATA=1;                           /*释放数据线 */
  53   1        SCK=1;                            /*第9位作为响应位*/
  54   1        error=DATA;                       /*检测响应情况,如果有响应数据线就会被SHT10拉低*/
  55   1        SCK=0;        
C51 COMPILER V8.05a   SHT11                                                                08/06/2008 10:52:27 PAGE 2   

  56   1        return error;                     /*返回1表示没响应*/
  57   1      }
  58          
  59          char read_byte(unsigned char ack)
  60          { 
  61   1        unsigned char i,val=0;
  62   1        DATA=1;                           /*释放数据线 */
  63   1        for (i=0x80;i>0;i/=2)             /*连续向右移动8位*/
  64   1        { SCK=1;                          /*clk for SENSI-BUS*/
  65   2          if (DATA) val=(val | i);        /*read bit */ 
  66   2          SCK=0;                                       
  67   2        }
  68   1        DATA=!ack;                        /*当ack=1时拉低数据线*/
  69   1        SCK=1;                            /*clk #9 for ack*/
  70   1        _nop_();_nop_();_nop_();          /*pulswith approx. 5 us */
  71   1        SCK=0;                                                    
  72   1        DATA=1;                           /*释放数据线*/
  73   1        return val;
  74   1      }
  75          
  76          void transstart(void)
  77          {
  78   1          DATA=1; 
  79   1          SCK=0;                   //初始状态
  80   1          _nop_();
  81   1          SCK=1;
  82   1          _nop_();
  83   1          DATA=0;
  84   1          _nop_();
  85   1          SCK=0;
  86   1          _nop_();_nop_();_nop_();
  87   1          SCK=1;
  88   1          _nop_();
  89   1          DATA=1;
  90   1              _nop_();
  91   1          SCK=0;
  92   1      }
  93          
  94          void connectionreset(void)//复位:当DATA线处于高低平时,触发SCK9次以上(含9次),此后应接发一个"传输开始"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -