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

📄 main.s90

📁 达拉斯 1-Wire 主机通信 这份资料展示了如何把 1-Wire 主机通信在应用到一个AVR系统中
💻 S90
📖 第 1 页 / 共 3 页
字号:
//////////////////////////////////////////////////////////////////////////////
//                                                                           /
// IAR Atmel AVR C/EC++ Compiler V3.20A/W32            19/Aug/2004  16:08:03 /
// 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.s90   /
//                                                                           /
//                                                                           /
//////////////////////////////////////////////////////////////////////////////

        NAME main

        RTMODEL "__64bit_doubles", "disabled"
        RTMODEL "__cpu", "3"
        RTMODEL "__cpu_name", "ATmega32"
        RTMODEL "__enhanced_core", "enabled"
        RTMODEL "__has_elpm", "false"
        RTMODEL "__memory_model", "2"
        RTMODEL "__rt_version", "3"

        RSEG CSTACK:DATA:NOROOT(0)
        RSEG RSTACK:DATA:NOROOT(0)

        EXTERN ?EPILOGUE_B15_L09
        EXTERN ?EPILOGUE_B4_L09
        EXTERN ?EPILOGUE_B6_L09
        EXTERN ?PROLOGUE15_L09
        EXTERN ?PROLOGUE4_L09
        EXTERN ?PROLOGUE6_L09
        EXTERN ?PROLOGUE7_L09
        EXTERN ?Register_R10_is_cg_reg
        EXTERN ?Register_R11_is_cg_reg
        EXTERN ?Register_R12_is_cg_reg
        EXTERN ?Register_R13_is_cg_reg
        EXTERN ?Register_R14_is_cg_reg
        EXTERN ?Register_R4_is_cg_reg
        EXTERN ?Register_R5_is_cg_reg
        EXTERN ?Register_R6_is_cg_reg
        EXTERN ?Register_R7_is_cg_reg
        EXTERN ?Register_R8_is_cg_reg
        EXTERN ?Register_R9_is_cg_reg
        EXTERN ?S_EC_MUL_L02
        EXTERN ?need_segment_init

        PUBWEAK `?<Segment init: NEAR_Z>`
        PUBLIC DS1820_ReadTemperature
        FUNCTION DS1820_ReadTemperature,021203H
        LOCFRAME CSTACK, 6, STACK
        LOCFRAME RSTACK, 2, STACK
        PUBLIC DS2890_SetWiperPosition
        FUNCTION DS2890_SetWiperPosition,021203H
        LOCFRAME CSTACK, 4, STACK
        LOCFRAME RSTACK, 2, STACK
        PUBLIC FindFamily
        FUNCTION FindFamily,0203H
        LOCFRAME RSTACK, 2, STACK
        PUBLIC SearchBuses
        FUNCTION SearchBuses,021203H
        LOCFRAME CSTACK, 15, STACK
        LOCFRAME RSTACK, 4, STACK
        PUBWEAK _A_ACSR
        PUBWEAK _A_ADC
        PUBWEAK _A_ADCSRA
        PUBWEAK _A_ADMUX
        PUBWEAK _A_ASSR
        PUBWEAK _A_DDRA
        PUBWEAK _A_DDRB
        PUBWEAK _A_DDRC
        PUBWEAK _A_DDRD
        PUBWEAK _A_EEAR
        PUBWEAK _A_EECR
        PUBWEAK _A_EEDR
        PUBWEAK _A_GICR
        PUBWEAK _A_GIFR
        PUBWEAK _A_ICR1
        PUBWEAK _A_MCUCR
        PUBWEAK _A_MCUCSR
        PUBWEAK _A_OCR0
        PUBWEAK _A_OCR1A
        PUBWEAK _A_OCR1B
        PUBWEAK _A_OCR2
        PUBWEAK _A_OSCCAL
        PUBWEAK _A_PINA
        PUBWEAK _A_PINB
        PUBWEAK _A_PINC
        PUBWEAK _A_PIND
        PUBWEAK _A_PORTA
        PUBWEAK _A_PORTB
        PUBWEAK _A_PORTC
        PUBWEAK _A_PORTD
        PUBWEAK _A_SFIOR
        PUBWEAK _A_SP
        PUBWEAK _A_SPCR
        PUBWEAK _A_SPDR
        PUBWEAK _A_SPMCR
        PUBWEAK _A_SPSR
        PUBWEAK _A_SREG
        PUBWEAK _A_TCCR0
        PUBWEAK _A_TCCR1A
        PUBWEAK _A_TCCR1B
        PUBWEAK _A_TCCR2
        PUBWEAK _A_TCNT0
        PUBWEAK _A_TCNT1
        PUBWEAK _A_TCNT2
        PUBWEAK _A_TIFR
        PUBWEAK _A_TIMSK
        PUBWEAK _A_TWAR
        PUBWEAK _A_TWBR
        PUBWEAK _A_TWCR
        PUBWEAK _A_TWDR
        PUBWEAK _A_TWSR
        PUBWEAK _A_UBRRH
        PUBWEAK _A_UBRRL
        PUBWEAK _A_UCSRA
        PUBWEAK _A_UCSRB
        PUBWEAK _A_UDR
        PUBWEAK _A_WDTCR
        PUBWEAK __?EEARH
        PUBWEAK __?EEARL
        PUBWEAK __?EECR
        PUBWEAK __?EEDR
        PUBLIC main
        FUNCTION main,021a03H
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
        
        CFI Names cfiNames0
        CFI StackFrame CFA_Y Y DATA
        CFI StackFrame CFA_SP SP DATA
        CFI VirtualResource ?RetPad:1, ?RetHigh:8, ?RetLow:8, ?Ret:17
        CFI Resource R0:8, R1:8, R2:8, R3:8, R4:8, R5:8, R6:8, R7:8, R8:8, R9:8
        CFI Resource R10:8, R11:8, R12:8, R13:8, R14:8, R15:8, R16:8, R17:8
        CFI Resource R18:8, R19:8, R20:8, R21:8, R22:8, R23:8, R24:8, R25:8
        CFI Resource R26:8, R27:8, R28:8, R29:8, R30:8, R31:8
        CFI Resource ?RetHighByteMask:8, SP:16, SPH:8, SPL:8, Y:16
        CFI ResourceParts ?Ret ?RetHigh, ?RetLow, ?RetPad
        CFI ResourceParts SP SPH, SPL
        CFI ResourceParts Y R29, R28
        CFI EndNames cfiNames0
        
        CFI Common cfiCommon0 Using cfiNames0
        CFI CodeAlign 1
        CFI DataAlign 1
        CFI ReturnAddress ?Ret CODE
        CFI CFA_Y Y+0
        CFI CFA_SP SP+2
        CFI ?RetPad 0
        CFI ?RetHigh and(load(1, DATA, sub(CFA_SP, 1)), ?RetHighByteMask)
        CFI ?RetLow Frame(CFA_SP, 0)
        CFI ?Ret Concat
        CFI R0 Undefined
        CFI R1 Undefined
        CFI R2 Undefined
        CFI R3 Undefined
        CFI R4 SameValue
        CFI R5 SameValue
        CFI R6 SameValue
        CFI R7 SameValue
        CFI R8 SameValue
        CFI R9 SameValue
        CFI R10 SameValue
        CFI R11 SameValue
        CFI R12 SameValue
        CFI R13 SameValue
        CFI R14 SameValue
        CFI R15 SameValue
        CFI R16 Undefined
        CFI R17 Undefined
        CFI R18 Undefined
        CFI R19 Undefined
        CFI R20 Undefined
        CFI R21 Undefined
        CFI R22 Undefined
        CFI R23 Undefined
        CFI R24 SameValue
        CFI R25 SameValue
        CFI R26 SameValue
        CFI R27 SameValue
        CFI R28 Undefined
        CFI R29 Undefined
        CFI R30 Undefined
        CFI R31 Undefined
        CFI ?RetHighByteMask SameValue
        CFI SPH Undefined
        CFI SPL Undefined
        CFI EndCommon cfiCommon0
        
        EXTERN OWI_Init
        FUNCTION OWI_Init,0202H
        EXTERN OWI_DetectPresence
        FUNCTION OWI_DetectPresence,0202H
        EXTERN memcpy
        FUNCTION memcpy,010202H
        EXTERN OWI_SearchRom
        FUNCTION OWI_SearchRom,0202H
        EXTERN OWI_CheckRomCRC
        FUNCTION OWI_CheckRomCRC,0202H
        EXTERN OWI_MatchRom
        FUNCTION OWI_MatchRom,0202H
        EXTERN OWI_SendByte
        FUNCTION OWI_SendByte,0202H
        EXTERN OWI_ReadBit
        FUNCTION OWI_ReadBit,0202H
        EXTERN OWI_ReceiveByte
        FUNCTION OWI_ReceiveByte,0202H

// 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  */

        RSEG CODE:CODE:NOROOT(1)
//   84 void main(void)
main:
        CFI Block cfiBlock0 Using cfiCommon0
        CFI Function main
//   85 {
        FUNCALL main, OWI_Init
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
        FUNCALL main, SearchBuses
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
        FUNCALL main, FindFamily
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
        FUNCALL main, FindFamily
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
        FUNCALL main, DS1820_ReadTemperature
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
        FUNCALL main, DS2890_SetWiperPosition
        LOCFRAME CSTACK, 7, STACK
        LOCFRAME RSTACK, 2, STACK
	CALL	?PROLOGUE7_L09
        CFI R6 Frame(CFA_Y, -1)
        CFI R5 Frame(CFA_Y, -2)
        CFI R4 Frame(CFA_Y, -3)
        CFI R27 Frame(CFA_Y, -4)
        CFI R26 Frame(CFA_Y, -5)
        CFI R25 Frame(CFA_Y, -6)
        CFI R24 Frame(CFA_Y, -7)
        CFI CFA_Y Y+7
	REQUIRE	?Register_R4_is_cg_reg
	REQUIRE	?Register_R5_is_cg_reg
	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;
	CLR	R4
	CLR	R5
//   90     unsigned char wiperPos = 0;
	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;
	LDI	R16,255
	OUT	0x17,R16
//   95 
//   96     OWI_Init(BUSES);
	LDI	R16,3
	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:
	LDI	R19,3
	LDI	R18,8
	LDI	R16,LOW(??devices)
	LDI	R17,(??devices) >> 8
	RCALL	SearchBuses
	TST	R16
	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);
	LDI	R17,8
	LDI	R18,LOW(??devices)
	LDI	R19,(??devices) >> 8
	LDI	R16,16
	RCALL	FindFamily
	MOVW	R25 : R24,R17 : R16
//  106     ds2890 = FindFamily(DS2890_FAMILY_ID, devices, MAX_DEVICES);
	LDI	R17,8
	LDI	R18,LOW(??devices)
	LDI	R19,(??devices) >> 8
	LDI	R16,44
	RCALL	FindFamily
	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:
	MOV	R16,R24
	OR	R16,R25
	BREQ	??main_2
//  115         {
//  116             temperature = DS1820_ReadTemperature((*ds1820).bus, (*ds1820).id);
	MOVW	R19 : R18,R25 : R24
	SUBI	R18,255
	SBCI	R19,255
	MOVW	R31 : R30,R25 : R24
	LD	R16,Z
	RCALL	DS1820_ReadTemperature
	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:
	MOV	R16,R26
	OR	R16,R27
	BREQ	??main_3
//  121         {
//  122             DS2890_SetWiperPosition(wiperPos++, (*ds2890).bus, (*ds2890).id);
	MOVW	R19 : R18,R27 : R26
	SUBI	R18,255
	SBCI	R19,255
	LD	R17,X
	MOV	R16,R6
	RCALL	DS2890_SetWiperPosition
	INC	R6
//  123         }
//  124         
//  125         // Discard lsb of temperature and output to PORTB.
//  126         PORTB = ~(temperature >> 1);
??main_3:
	MOVW	R17 : R16,R5 : R4
	ASR	R17
	ROR	R16
	COM	R16
	OUT	0x18,R16
	RJMP	??main_1
        CFI EndBlock cfiBlock0
//  127     }
//  128 }

        RSEG NEAR_Z:DATA:ROOT(0)
	REQUIRE `?<Segment init: NEAR_Z>`
??devices:
        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  */

⌨️ 快捷键说明

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