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

📄 owihighlevelfunctions.lst

📁 达拉斯 1-Wire 主机通信 这份资料展示了如何把 1-Wire 主机通信在应用到一个AVR系统中
💻 LST
📖 第 1 页 / 共 3 页
字号:
##############################################################################
#                                                                            #
# IAR Atmel AVR C/EC++ Compiler V3.20A/W32             19/Aug/2004  16:18:27 #
# Copyright 1996-2004 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Source file  =  Z:\qvcs\AVR318 Dallas 1-wire Communication              #
#                    Interface\Source Code\IAR\polled\OWIHighLevelFunctions. #
#                    c                                                       #
#    Command line =  --cpu=m32 -ms -o "Z:\qvcs\AVR318 Dallas 1-wire          #
#                    Communication Interface\Source                          #
#                    Code\IAR\polled\Debug\Obj\" -lC "Z:\qvcs\AVR318 Dallas  #
#                    1-wire Communication Interface\Source                   #
#                    Code\IAR\polled\Debug\List\" -lA "Z:\qvcs\AVR318        #
#                    Dallas 1-wire Communication Interface\Source            #
#                    Code\IAR\polled\Debug\List\" --initializers_in_flash    #
#                    --root_variables -z2 --no_cse --no_inline               #
#                    --no_code_motion --no_cross_call --no_clustering        #
#                    --debug -DENABLE_BIT_DEFINITIONS -e -I "C:\Program      #
#                    Files\IAR Systems\Embedded Workbench 3.2\avr\INC\" -I   #
#                    "C:\Program Files\IAR Systems\Embedded Workbench        #
#                    3.2\avr\INC\CLIB\" --eeprom_size 1024 "Z:\qvcs\AVR318   #
#                    Dallas 1-wire Communication Interface\Source            #
#                    Code\IAR\polled\OWIHighLevelFunctions.c"                #
#    List file    =  Z:\qvcs\AVR318 Dallas 1-wire Communication              #
#                    Interface\Source Code\IAR\polled\Debug\List\OWIHighLeve #
#                    lFunctions.lst                                          #
#    Object file  =  Z:\qvcs\AVR318 Dallas 1-wire Communication              #
#                    Interface\Source Code\IAR\polled\Debug\Obj\OWIHighLevel #
#                    Functions.r90                                           #
#                                                                            #
#                                                                            #
##############################################################################

Z:\qvcs\AVR318 Dallas 1-wire Communication Interface\Source Code\IAR\polled\OWIHighLevelFunctions.c
      1          // This file has been prepared for Doxygen automatic documentation generation.
      2          /*! \file ********************************************************************
      3          *
      4          * Atmel Corporation
      5          *
      6          * \li File:               OWIHighLevelFunctions.c
      7          * \li Compiler:           IAR EWAAVR 3.20a
      8          * \li Support mail:       avr@atmel.com
      9          *
     10          * \li Supported devices:  All AVRs.
     11          *
     12          * \li Application Note:   AVR318 - Dallas 1-Wire(R) master.
     13          *                         
     14          *
     15          * \li Description:        High level functions for transmission of full bytes
     16          *                         on the 1-Wire(R) bus and implementations of ROM
     17          *                         commands.
     18          *
     19          *                         $Revision: 1.6 $
     20          *                         $Date: Thursday, August 19, 2004 09:02:02 UTC $
     21          ****************************************************************************/
     22          
     23          #include <ioavr.h>
     24          
     25          #include "OWIHighLevelFunctions.h"
     26          #include "OWIBitFunctions.h"
     27          #include "OWIPolled.h"
     28          
     29          
     30          /*! \brief  Sends one byte of data on the 1-Wire(R) bus(es).
     31           *  
     32           *  This function automates the task of sending a complete byte
     33           *  of data on the 1-Wire bus(es).
     34           *
     35           *  \param  data    The data to send on the bus(es).
     36           *  
     37           *  \param  pins    A bitmask of the buses to send the data to.
     38           */

   \                                 In segment CODE, align 2, keep-with-next
     39          void OWI_SendByte(unsigned char data, unsigned char pins)
   \                     OWI_SendByte:
     40          {
   \   00000000   ........                   CALL    ?PROLOGUE4_L09
   \   00000004   2FA0                       MOV     R26,R16
   \   00000006   2F91                       MOV     R25,R17
     41              unsigned char temp;
     42              unsigned char i;
     43              
     44              // Do once for each bit
     45              for (i = 0; i < 8; i++)
   \   00000008   E080                       LDI     R24,0
   \                     ??OWI_SendByte_0:
   \   0000000A   3088                       CPI     R24,8
   \   0000000C   F478                       BRCC    ??OWI_SendByte_1
     46              {
     47                  // Determine if lsb is '0' or '1' and transmit corresponding
     48                  // waveform on the bus.
     49                  temp = data & 0x01;
   \   0000000E   2F0A                       MOV     R16,R26
   \   00000010   7001                       ANDI    R16,0x01
   \   00000012   2FB0                       MOV     R27,R16
     50                  if (temp)
   \   00000014   23BB                       TST     R27
   \   00000016   F021                       BREQ    ??OWI_SendByte_2
     51                  {
     52                      OWI_WriteBit1(pins);
   \   00000018   2F09                       MOV     R16,R25
   \   0000001A   ........                   CALL    OWI_WriteBit1
   \   0000001E   C003                       RJMP    ??OWI_SendByte_3
     53                  }
     54                  else
     55                  {
     56                      OWI_WriteBit0(pins);
   \                     ??OWI_SendByte_2:
   \   00000020   2F09                       MOV     R16,R25
   \   00000022   ........                   CALL    OWI_WriteBit0
     57                  }
     58                  // Right shift the data to get next bit.
     59                  data >>= 1;
   \                     ??OWI_SendByte_3:
   \   00000026   95A6                       LSR     R26
     60              }
   \   00000028   9583                       INC     R24
   \   0000002A   CFEF                       RJMP    ??OWI_SendByte_0
     61          }
   \                     ??OWI_SendByte_1:
   \   0000002C   E0E4                       LDI     R30,4
   \   0000002E   ........                   JMP     ?EPILOGUE_B4_L09
     62          
     63          
     64          /*!  \brief  Receives one byte of data from the 1-Wire(R) bus.
     65           *
     66           *  This function automates the task of receiving a complete byte 
     67           *  of data from the 1-Wire bus.
     68           *
     69           *  \param  pin     A bitmask of the bus to read from.
     70           *  
     71           *  \return     The byte read from the bus.
     72           */

   \                                 In segment CODE, align 2, keep-with-next
     73          unsigned char OWI_ReceiveByte(unsigned char pin)
   \                     OWI_ReceiveByte:
     74          {
   \   00000000   ........                   CALL    ?PROLOGUE3_L09
   \   00000004   2FA0                       MOV     R26,R16
     75              unsigned char data;
     76              unsigned char i;
     77          
     78              // Clear the temporary input variable.
     79              data = 0x00;
   \   00000006   E090                       LDI     R25,0
     80              
     81              // Do once for each bit
     82              for (i = 0; i < 8; i++)
   \   00000008   E080                       LDI     R24,0
   \                     ??OWI_ReceiveByte_0:
   \   0000000A   3088                       CPI     R24,8
   \   0000000C   F448                       BRCC    ??OWI_ReceiveByte_1
     83              {
     84                  // Shift temporary input variable right.
     85                  data >>= 1;
   \   0000000E   9596                       LSR     R25
     86                  // Set the msb if a '1' value is read from the bus.
     87                  // Leave as it is ('0') else.
     88                  if (OWI_ReadBit(pin))
   \   00000010   2F0A                       MOV     R16,R26
   \   00000012   ........                   CALL    OWI_ReadBit
   \   00000016   2300                       TST     R16
   \   00000018   F009                       BREQ    ??OWI_ReceiveByte_2
     89                  {
     90                      // Set msb
     91                      data |= 0x80;
   \   0000001A   6890                       ORI     R25,0x80
     92                  }
     93              }
   \                     ??OWI_ReceiveByte_2:
   \   0000001C   9583                       INC     R24
   \   0000001E   CFF5                       RJMP    ??OWI_ReceiveByte_0
     94              return data;
   \                     ??OWI_ReceiveByte_1:
   \   00000020   2F09                       MOV     R16,R25
   \   00000022   E0E3                       LDI     R30,3
   \   00000024   ........                   JMP     ?EPILOGUE_B3_L09
     95          }
     96          
     97          
     98          /*! \brief   Sends the SKIP ROM command to the 1-Wire bus(es).
     99           *
    100           *  \param  pins    A bitmask of the buses to send the SKIP ROM command to.
    101           */

   \                                 In segment CODE, align 2, keep-with-next
    102          void OWI_SkipRom(unsigned char pins)
   \                     OWI_SkipRom:
    103          {
   \   00000000   938A                       ST      -Y,R24
   \   00000002   2F80                       MOV     R24,R16
    104              // Send the SKIP ROM command on the bus.
    105              OWI_SendByte(OWI_ROM_SKIP, pins);
   \   00000004   2F18                       MOV     R17,R24
   \   00000006   EC0C                       LDI     R16,204
   \   00000008   ....                       RCALL   OWI_SendByte
    106          }
   \   0000000A   9189                       LD      R24,Y+
   \   0000000C   9508                       RET
    107          
    108          
    109          /*! \brief  Sends the READ ROM command and reads back the ROM id.
    110           *
    111           *  \param  romValue    A pointer where the id will be placed.
    112           *
    113           *  \param  pin     A bitmask of the bus to read from.
    114           */

   \                                 In segment CODE, align 2, keep-with-next
    115          void OWI_ReadRom(unsigned char * romValue, unsigned char pin)
   \                     OWI_ReadRom:
    116          {
   \   00000000   ........                   CALL    ?PROLOGUE4_L09
   \   00000004   01D8                       MOVW    R27 : R26,R17 : R16
   \   00000006   2F92                       MOV     R25,R18
    117              unsigned char bytesLeft = 8;
   \   00000008   E088                       LDI     R24,8
    118          
    119              // Send the READ ROM command on the bus.
    120              OWI_SendByte(OWI_ROM_READ, pin);
   \   0000000A   2F19                       MOV     R17,R25
   \   0000000C   E303                       LDI     R16,51
   \   0000000E   ....                       RCALL   OWI_SendByte
    121              
    122              // Do 8 times.
    123              while (bytesLeft > 0)
   \                     ??OWI_ReadRom_0:
   \   00000010   3081                       CPI     R24,1
   \   00000012   F038                       BRCS    ??OWI_ReadRom_1
    124              {
    125                  // Place the received data in memory.
    126                  *romValue++ = OWI_ReceiveByte(pin);
   \   00000014   2F09                       MOV     R16,R25
   \   00000016   ....                       RCALL   OWI_ReceiveByte
   \   00000018   01FD                       MOVW    R31 : R30,R27 : R26
   \   0000001A   8300                       ST      Z,R16
   \   0000001C   9611                       ADIW    R27 : R26,1
    127                  bytesLeft--;
   \   0000001E   958A                       DEC     R24
   \   00000020   CFF7                       RJMP    ??OWI_ReadRom_0
    128              }
    129          }
   \                     ??OWI_ReadRom_1:
   \   00000022   E0E4                       LDI     R30,4
   \   00000024   ........                   JMP     ?EPILOGUE_B4_L09
    130          
    131          
    132          /*! \brief  Sends the MATCH ROM command and the ROM id to match against.
    133           *
    134           *  \param  romValue    A pointer to the ID to match against.
    135           *
    136           *  \param  pins    A bitmask of the buses to perform the MATCH ROM command on.
    137           */

   \                                 In segment CODE, align 2, keep-with-next
    138          void OWI_MatchRom(unsigned char * romValue, unsigned char pins)
   \                     OWI_MatchRom:
    139          {
   \   00000000   ........                   CALL    ?PROLOGUE4_L09
   \   00000004   01D8                       MOVW    R27 : R26,R17 : R16
   \   00000006   2F92                       MOV     R25,R18
    140              unsigned char bytesLeft = 8;   
   \   00000008   E088                       LDI     R24,8
    141              
    142              // Send the MATCH ROM command.
    143              OWI_SendByte(OWI_ROM_MATCH, pins);
   \   0000000A   2F19                       MOV     R17,R25
   \   0000000C   E505                       LDI     R16,85
   \   0000000E   ....                       RCALL   OWI_SendByte
    144          
    145              // Do once for each byte.
    146              while (bytesLeft > 0)
   \                     ??OWI_MatchRom_0:
   \   00000010   3081                       CPI     R24,1
   \   00000012   F038                       BRCS    ??OWI_MatchRom_1
    147              {
    148                  // Transmit 1 byte of the ID to match.
    149                  OWI_SendByte(*romValue++, pins);
   \   00000014   2F19                       MOV     R17,R25
   \   00000016   01FD                       MOVW    R31 : R30,R27 : R26
   \   00000018   8100                       LD      R16,Z
   \   0000001A   ....                       RCALL   OWI_SendByte
   \   0000001C   9611                       ADIW    R27 : R26,1
    150                  bytesLeft--;
   \   0000001E   958A                       DEC     R24
   \   00000020   CFF7                       RJMP    ??OWI_MatchRom_0
    151              }
    152          }
   \                     ??OWI_MatchRom_1:
   \   00000022   E0E4                       LDI     R30,4
   \   00000024   ........                   JMP     ?EPILOGUE_B4_L09
    153          
    154          
    155          /*! \brief  Sends the SEARCH ROM command and returns 1 id found on the 
    156           *          1-Wire(R) bus.
    157           *
    158           *  \param  bitPattern      A pointer to an 8 byte char array where the 
    159           *                          discovered identifier will be placed. When 
    160           *                          searching for several slaves, a copy of the 
    161           *                          last found identifier should be supplied in 

⌨️ 快捷键说明

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