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

📄 i2c_1621.lst

📁 时间触发嵌入式系统设计模式:使用8051系列微控制器开发可靠应用
💻 LST
字号:
C51 COMPILER V6.10  I2C_1621                                                               04/09/2001 15:01:27 PAGE 1   


C51 COMPILER V6.10, COMPILATION OF MODULE I2C_1621
OBJECT MODULE PLACED IN .\I2C_1621.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\I2C_1621.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             I2C_1621.C (v1.00)
   4          
   5            ------------------------------------------------------------------
   6          
   7             I2C-based library for DS1621 temperature sensor.
   8          
   9          
  10             COPYRIGHT
  11             ---------
  12          
  13             This code is from the book:
  14          
  15             PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
  16             [Pearson Education, 2001; ISBN: 0-201-33138-1].
  17          
  18             This code is copyright (c) 2001 by Michael J. Pont.
  19           
  20             See book for copyright details and other information.
  21          
  22          -*------------------------------------------------------------------*/
  23          
  24          #include "Main.h"
  25          
  26          #include "I2C_core.h"
  27          #include "I2C_1621.h"
  28          #include "Delay_T0.h"
  29          
  30          // ------ Public variable declarations -----------------------------
  31          
  32          extern tByte Temperature_G;
  33          extern tByte Error_code_G;
  34          
  35          // ------ Private constants ----------------------------------------
  36          
  37          #define I2C_DS1621_ID   0x90    
  38          
  39          
  40          /*------------------------------------------------------------------*-
  41          
  42            I2C_Init_Temperature_DS1621()
  43          
  44            Sets the sensor to 'continuous convert' mode to allow 
  45            temperature readings to be subsequently obtained.
  46          
  47          -*------------------------------------------------------------------*/
  48          void I2C_Init_Temperature_DS1621(void)
  49             {
  50   1         I2C_Send_Start();   // Generate START condition
  51   1      
  52   1         // Send SLAVE address with write request
  53   1         if (I2C_Write_Byte(I2C_DS1621_ID | I2C_WRITE))
  54   1            {
  55   2            Error_code_G = ERROR_I2C_DS1621; 
C51 COMPILER V6.10  I2C_1621                                                               04/09/2001 15:01:27 PAGE 2   

  56   2            return;
  57   2            }
  58   1      
  59   1         // Send control byte :
  60   1         // configure command
  61   1         if (I2C_Write_Byte(0xAC))
  62   1            {
  63   2            Error_code_G = ERROR_I2C_DS1621; 
  64   2            return;
  65   2            }
  66   1      
  67   1         // Send configuration data - CONTINUOUS mode
  68   1         if (I2C_Write_Byte(0x00)) 
  69   1            {
  70   2            Error_code_G = ERROR_I2C_DS1621;
  71   2            return;
  72   2            }
  73   1      
  74   1         I2C_Send_Stop();    // Generate STOP condition
  75   1      
  76   1         // Must delay here to allow EEPROM (in sensor)
  77   1         // to store these data.  Sheet says 10ms.
  78   1         Hardware_Delay_T0(100);  
  79   1      
  80   1         // Now start temperature conversions
  81   1         I2C_Send_Start();   // Generate START condition
  82   1      
  83   1         // Send SLAVE address with write request
  84   1         if (I2C_Write_Byte(I2C_DS1621_ID | I2C_WRITE))
  85   1            {
  86   2            Error_code_G = ERROR_I2C_DS1621;
  87   2            return;
  88   2            }
  89   1      
  90   1          // Send command data - start converting
  91   1          if (I2C_Write_Byte(0xEE)) 
  92   1             {
  93   2             Error_code_G = ERROR_I2C_DS1621;
  94   2             return;
  95   2             }
  96   1      
  97   1         I2C_Send_Stop();    // Generate STOP condition
  98   1         }
  99          
 100            
 101          /*------------------------------------------------------------------*-
 102          
 103            I2C_Read_Temperature_DS1621()
 104          
 105            The sensor samples continuously (around 1 new value per second).
 106            We obtain the latest value.
 107          
 108          -*------------------------------------------------------------------*/
 109          void I2C_Read_Temperature_DS1621(void)
 110             {
 111   1         tByte result = 0;
 112   1      
 113   1         I2C_Send_Start();   // Generate START condition
 114   1      
 115   1         // Send DS1621 device address (with write access request)
 116   1         if (I2C_Write_Byte(I2C_DS1621_ID | I2C_WRITE))
 117   1            {
C51 COMPILER V6.10  I2C_1621                                                               04/09/2001 15:01:27 PAGE 3   

 118   2            Error_code_G = ERROR_I2C_DS1621;
 119   2            return;
 120   2            }
 121   1      
 122   1          // Send command - Read Temperature (0xAA)
 123   1          if (I2C_Write_Byte(0xAA))
 124   1             {
 125   2            Error_code_G = ERROR_I2C_DS1621;
 126   2             return;
 127   2             }
 128   1      
 129   1         I2C_Send_Start();   // Generate START condition (again)
 130   1      
 131   1         // Send DS1621 device address (with READ access request this time)
 132   1         if (I2C_Write_Byte(I2C_DS1621_ID | I2C_READ))
 133   1            {
 134   2            Error_code_G = ERROR_I2C_DS1621;
 135   2            return;
 136   2            }
 137   1      
 138   1          // Receive first (MS) byte from I2C bus
 139   1          Temperature_G = I2C_Read_Byte();
 140   1          I2C_Send_Master_Ack();     // Perform a MASTER ACK
 141   1      
 142   1          // Here we require temperature only accurate to 1 degree C
 143   1          // - we discard LS byte (perform a dummy read)
 144   1          I2C_Read_Byte();
 145   1          I2C_Send_Master_NAck();    // Perform a MASTER NACK
 146   1      
 147   1          I2C_Send_Stop();    // Generate STOP condition
 148   1          }
 149          
 150          /*------------------------------------------------------------------*-
 151            ---- END OF FILE -------------------------------------------------
 152          -*------------------------------------------------------------------*/
 153          
 154          
 155          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    143    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       1
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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