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

📄 main.lst

📁 达拉斯 1-Wire 主机通信 这份资料展示了如何把 1-Wire 主机通信在应用到一个AVR系统中
💻 LST
📖 第 1 页 / 共 4 页
字号:
##############################################################################
#                                                                            #
# IAR Atmel AVR C/EC++ Compiler V3.20A/W32             19/Aug/2004  16:08:04 #
# Copyright 1996-2004 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Source file  =  Z:\qvcs\AVR318 Dallas 1-wire Communication              #
#                    Interface\Source Code\IAR\polled\main.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\main.c"                                 #
#    List file    =  Z:\qvcs\AVR318 Dallas 1-wire Communication              #
#                    Interface\Source Code\IAR\polled\Debug\List\main.lst    #
#    Object file  =  Z:\qvcs\AVR318 Dallas 1-wire Communication              #
#                    Interface\Source Code\IAR\polled\Debug\Obj\main.r90     #
#                                                                            #
#                                                                            #
##############################################################################

Z:\qvcs\AVR318 Dallas 1-wire Communication Interface\Source Code\IAR\polled\main.c
      1          // This file has been prepared for Doxygen automatic documentation generation.
      2          /*! \file ********************************************************************
      3          *
      4          * Atmel Corporation
      5          *
      6          * \li File:               main.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:        Example on how to use the 1-Wire(R) interface
     16          *                         master.
     17          *
     18          *                         $Revision: 1.6 $
     19          *                         $Date: Thursday, August 19, 2004 09:02:02 UTC $
     20          ****************************************************************************/
     21          
     22          #include <ioavr.h>
     23          #include <inavr.h>
     24          
     25          #include "OWIPolled.h"
     26          #include "OWIHighLevelFunctions.h"
     27          #include "OWIBitFunctions.h"
     28          #include "..\common_files\OWIcrc.h"
     29          
     30          #include <string.h> // Used for memcpy.
     31          
     32          
     33          // Defines used only in code example.
     34          #define DS1820_FAMILY_ID                0x10 
     35          #define DS1820_START_CONVERSION         0x44
     36          #define DS1820_READ_SCRATCHPAD          0xbe
     37          #define DS1820_ERROR                    -1000   // Return code. Outside temperature range.
     38          
     39          #define DS2890_FAMILY_ID                0x2c
     40          #define DS2890_WRITE_CONTROL_REGISTER   0X55
     41          #define DS2890_RELEASE_CODE             0x96
     42          #define DS2890_WRITE_POSITION           0x0f
     43          
     44          #define SEARCH_SUCCESSFUL               0x00
     45          #define SEARCH_CRC_ERROR                0x01
     46          
     47          #define FALSE       0
     48          #define TRUE        1
     49          
     50          #define MAX_DEVICES 8       //!< Max number of devices to search for.
     51          
     52          #define BUSES   (OWI_PIN_0 | OWI_PIN_1) //!< Buses to search.
     53          
     54          
     55          /*! \brief  Data type used to hold information about slave devices.
     56           *  
     57           *  The OWI_device data type holds information about what bus each device
     58           *  is connected to, and its 64 bit identifier.
     59           */
     60          typedef struct
     61          {
     62              unsigned char bus;      //!< A bitmask of the bus the device is connected to.
     63              unsigned char id[8];    //!< The 64 bit identifier.
     64          } OWI_device;
     65          
     66          
     67          // Prototypes of functions used in exemples.
     68          unsigned char SearchBuses(OWI_device * devices, unsigned char len, unsigned char buses);
     69          OWI_device * FindFamily(unsigned char familyID, OWI_device * devices, unsigned char size);
     70          signed int DS1820_ReadTemperature(unsigned char bus, unsigned char * id);
     71          void DS2890_SetWiperPosition(unsigned char position, unsigned char bus, unsigned char * id);
     72          
     73          
     74          /*! \brief  Example application for the polled drivers.
     75           *
     76           *  Example application for the software only and polled UART driver.
     77           *  This example application will find all devices (upper bounded by MAX_DEVICES) 
     78           *  on the buses defined by BUSES. It then tries to find either a DS1820 or DS2890 
     79           *  device on a bus, and communicate with them to read temperature (DS1820) or 
     80           *  set wiper position (DS2890).
     81           *  This example is not written in a very optimal way. It is merely intended to show
     82           *  how the polled 1-Wire(R) driver can be used.
     83           */

   \                                 In segment CODE, align 2, keep-with-next
     84          void main(void)
   \                     main:
     85          {
   \   00000000   ........                   CALL    ?PROLOGUE7_L09
   \   00000004                              REQUIRE ?Register_R4_is_cg_reg
   \   00000004                              REQUIRE ?Register_R5_is_cg_reg
   \   00000004                              REQUIRE ?Register_R6_is_cg_reg
     86              static OWI_device devices[MAX_DEVICES];
     87              OWI_device * ds1820;
     88              OWI_device * ds2890;
     89              signed int temperature = 0;
   \   00000004   2444                       CLR     R4
   \   00000006   2455                       CLR     R5
     90              unsigned char wiperPos = 0;
   \   00000008   2466                       CLR     R6
     91              
     92              // Initialize PORTB as output. Can be used to display values on
     93              // the LEDs on a STK500 development board.
     94              DDRB = 0xff;
   \   0000000A   EF0F                       LDI     R16,255
   \   0000000C   BB07                       OUT     0x17,R16
     95          
     96              OWI_Init(BUSES);
   \   0000000E   E003                       LDI     R16,3
   \   00000010   ........                   CALL    OWI_Init
     97              
     98              // Do the bus search until all ids are read without crc error.    
     99              while(SearchBuses(devices, MAX_DEVICES, BUSES) != SEARCH_SUCCESSFUL)
   \                     ??main_0:
   \   00000014   E033                       LDI     R19,3
   \   00000016   E028                       LDI     R18,8
   \   00000018   ....                       LDI     R16,LOW(??devices)
   \   0000001A   ....                       LDI     R17,(??devices) >> 8
   \   0000001C   ....                       RCALL   SearchBuses
   \   0000001E   2300                       TST     R16
   \   00000020   F7C9                       BRNE    ??main_0
    100              {
    101              
    102              }
    103              
    104              // See if there is a DS1820 or DS2890 on a bus.
    105              ds1820 = FindFamily(DS1820_FAMILY_ID, devices, MAX_DEVICES);
   \   00000022   E018                       LDI     R17,8
   \   00000024   ....                       LDI     R18,LOW(??devices)
   \   00000026   ....                       LDI     R19,(??devices) >> 8
   \   00000028   E100                       LDI     R16,16
   \   0000002A   ....                       RCALL   FindFamily
   \   0000002C   01C8                       MOVW    R25 : R24,R17 : R16
    106              ds2890 = FindFamily(DS2890_FAMILY_ID, devices, MAX_DEVICES);
   \   0000002E   E018                       LDI     R17,8
   \   00000030   ....                       LDI     R18,LOW(??devices)
   \   00000032   ....                       LDI     R19,(??devices) >> 8
   \   00000034   E20C                       LDI     R16,44
   \   00000036   ....                       RCALL   FindFamily
   \   00000038   01D8                       MOVW    R27 : R26,R17 : R16
    107              
    108              // Do something useful with the slave devices in an eternal loop.
    109              for (;;)
    110              {
    111                  // If there is a DS1820 temperature sensor on a bus, read the
    112                  // temperature.
    113                  // The DS1820 must have Vdd pin connected for this code to work.
    114                  if (ds1820 != NULL)
   \                     ??main_1:
   \   0000003A   2F08                       MOV     R16,R24
   \   0000003C   2B09                       OR      R16,R25
   \   0000003E   F039                       BREQ    ??main_2
    115                  {
    116                      temperature = DS1820_ReadTemperature((*ds1820).bus, (*ds1820).id);
   \   00000040   019C                       MOVW    R19 : R18,R25 : R24
   \   00000042   5F2F                       SUBI    R18,255
   \   00000044   4F3F                       SBCI    R19,255
   \   00000046   01FC                       MOVW    R31 : R30,R25 : R24
   \   00000048   8100                       LD      R16,Z
   \   0000004A   ....                       RCALL   DS1820_ReadTemperature
   \   0000004C   0128                       MOVW    R5 : R4,R17 : R16
    117                  }        
    118                  // If there is a DS2890 digital potentiometer, increment the
    119                  // wiper value.
    120                  if (ds2890 != NULL)
   \                     ??main_2:
   \   0000004E   2F0A                       MOV     R16,R26
   \   00000050   2B0B                       OR      R16,R27
   \   00000052   F039                       BREQ    ??main_3
    121                  {
    122                      DS2890_SetWiperPosition(wiperPos++, (*ds2890).bus, (*ds2890).id);
   \   00000054   019D                       MOVW    R19 : R18,R27 : R26
   \   00000056   5F2F                       SUBI    R18,255
   \   00000058   4F3F                       SBCI    R19,255
   \   0000005A   911C                       LD      R17,X
   \   0000005C   2D06                       MOV     R16,R6
   \   0000005E   ....                       RCALL   DS2890_SetWiperPosition
   \   00000060   9463                       INC     R6
    123                  }
    124                  
    125                  // Discard lsb of temperature and output to PORTB.
    126                  PORTB = ~(temperature >> 1);
   \                     ??main_3:
   \   00000062   0182                       MOVW    R17 : R16,R5 : R4
   \   00000064   9515                       ASR     R17
   \   00000066   9507                       ROR     R16
   \   00000068   9500                       COM     R16
   \   0000006A   BB08                       OUT     0x18,R16
   \   0000006C   CFE6                       RJMP    ??main_1
    127              }
    128          }

   \                                 In segment NEAR_Z, align 1, keep-with-next, root
   \   00000000                              REQUIRE `?<Segment init: NEAR_Z>`
   \                     ??devices:
   \   00000000                              DS 72
    129          
    130          
    131          /*! \brief  Perform a 1-Wire search
    132           *
    133           *  This function shows how the OWI_SearchRom function can be used to 
    134           *  discover all slaves on the bus. It will also CRC check the 64 bit
    135           *  identifiers.
    136           *
    137           *  \param  devices Pointer to an array of type OWI_device. The discovered 
    138           *                  devices will be placed from the beginning of this array.
    139           *
    140           *  \param  len     The length of the device array. (Max. number of elements).
    141           *
    142           *  \param  buses   Bitmask of the buses to perform search on.
    143           *
    144           *  \retval SEARCH_SUCCESSFUL   Search completed successfully.
    145           *  \retval SEARCH_CRC_ERROR    A CRC error occured. Probably because of noise
    146           *                              during transmission.
    147           */

   \                                 In segment CODE, align 2, keep-with-next
    148          unsigned char SearchBuses(OWI_device * devices, unsigned char len, unsigned char buses)
   \                     SearchBuses:
    149          {
   \   00000000   ........                   CALL    ?PROLOGUE15_L09
   \   00000004                              REQUIRE ?Register_R4_is_cg_reg
   \   00000004                              REQUIRE ?Register_R5_is_cg_reg
   \   00000004                              REQUIRE ?Register_R6_is_cg_reg
   \   00000004                              REQUIRE ?Register_R7_is_cg_reg
   \   00000004                              REQUIRE ?Register_R8_is_cg_reg
   \   00000004                              REQUIRE ?Register_R9_is_cg_reg
   \   00000004                              REQUIRE ?Register_R10_is_cg_reg
   \   00000004                              REQUIRE ?Register_R11_is_cg_reg
   \   00000004                              REQUIRE ?Register_R12_is_cg_reg
   \   00000004                              REQUIRE ?Register_R13_is_cg_reg
   \   00000004                              REQUIRE ?Register_R14_is_cg_reg
   \   00000004   01C8                       MOVW    R25 : R24,R17 : R16
   \   00000006   2ED2                       MOV     R13,R18
    150              unsigned char i, j;
    151              unsigned char presence;
    152              unsigned char * newID;
    153              unsigned char * currentID;
    154              unsigned char currentBus;
    155              unsigned char lastDeviation;
    156              unsigned char numDevices;
    157              
    158              // Initialize all addresses as zero, on bus 0 (does not exist).
    159              // Do a search on the bus to discover all addresses.    
    160              for (i = 0; i < len; i++)
   \   00000008   E0B0                       LDI     R27,0
   \                     ??SearchBuses_0:
   \   0000000A   15BD                       CP      R27,R13
   \   0000000C   F520                       BRCC    ??SearchBuses_1
    161              {
    162                  devices[i].bus = 0x00;
   \   0000000E   E000                       LDI     R16,0
   \   00000010   2E90                       MOV     R9,R16
   \   00000012   2F4B                       MOV     R20,R27
   \   00000014   E050                       LDI     R21,0
   \   00000016   E009                       LDI     R16,9
   \   00000018   E010                       LDI     R17,0
   \   0000001A   ........                   CALL    ?S_EC_MUL_L02

⌨️ 快捷键说明

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