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

📄 owicrc.s90

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

        NAME OWIcrc

        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_B4_L09
        EXTERN ?PROLOGUE4_L09

        PUBLIC OWI_CheckRomCRC
        FUNCTION OWI_CheckRomCRC,021203H
        LOCFRAME CSTACK, 4, STACK
        LOCFRAME RSTACK, 2, STACK
        PUBLIC OWI_ComputeCRC16
        FUNCTION OWI_ComputeCRC16,0203H
        LOCFRAME RSTACK, 2, STACK
        PUBLIC OWI_ComputeCRC8
        FUNCTION OWI_ComputeCRC8,0203H
        LOCFRAME RSTACK, 2, 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
        
        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
        
// Z:\qvcs\AVR318 Dallas 1-wire Communication Interface\Source Code\IAR\common_files\OWIcrc.c
//    1 // This file has been prepared for Doxygen automatic documentation generation.
//    2 /*! \file ********************************************************************
//    3 *
//    4 * Atmel Corporation
//    5 *
//    6 * \li File:               OWIcrc.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:        CRC algorithms typically used in a 1-Wire(R) 
//   16 *                         environment.
//   17 *
//   18 *                         $Revision: 1.6 $
//   19 *                         $Date: Thursday, August 19, 2004 09:02:00 UTC $
//   20 ****************************************************************************/
//   21 
//   22 #include "OWIcrc.h"
//   23 #include "OWIdefs.h"
//   24 
//   25 
//   26 /*! \brief  Compute the CRC8 value of a data set.
//   27  *
//   28  *  This function will compute the CRC8 or DOW-CRC of inData using seed
//   29  *  as inital value for the CRC.
//   30  *
//   31  *  \param  inData  One byte of data to compute CRC from.
//   32  *
//   33  *  \param  seed    The starting value of the CRC.
//   34  *
//   35  *  \return The CRC8 of inData with seed as initial value.
//   36  *
//   37  *  \note   Setting seed to 0 computes the crc8 of the inData.
//   38  *
//   39  *  \note   Constantly passing the return value of this function 
//   40  *          As the seed argument computes the CRC8 value of a
//   41  *          longer string of data.
//   42  */

        RSEG CODE:CODE:NOROOT(1)
//   43 unsigned char OWI_ComputeCRC8(unsigned char inData, unsigned char seed)
OWI_ComputeCRC8:
        CFI Block cfiBlock0 Using cfiCommon0
        CFI Function OWI_ComputeCRC8
//   44 {
	MOV	R19,R16
	MOV	R16,R17
//   45     unsigned char bitsLeft;
//   46     unsigned char temp;
//   47 
//   48     for (bitsLeft = 8; bitsLeft > 0; bitsLeft--)
	LDI	R17,8
??OWI_ComputeCRC8_0:
	CPI	R17,1
	BRCS	??OWI_ComputeCRC8_1
//   49     {
//   50         temp = ((seed ^ inData) & 0x01);
	MOV	R21,R16
	ANDI	R21,0x01
	MOV	R18,R19
	ANDI	R18,0x01
	EOR	R18,R21
	ANDI	R18,0x01
	MOV	R20,R18
//   51         if (temp == 0)
	TST	R20
	BRNE	??OWI_ComputeCRC8_2
//   52         {
//   53             seed >>= 1;
	LSR	R16
	RJMP	??OWI_ComputeCRC8_3
//   54         }
//   55         else
//   56         {
//   57             seed ^= 0x18;
??OWI_ComputeCRC8_2:
	LDI	R18,24
	EOR	R16,R18
//   58             seed >>= 1;
	LSR	R16
//   59             seed |= 0x80;
	ORI	R16,0x80
//   60         }
//   61         inData >>= 1;
??OWI_ComputeCRC8_3:
	LSR	R19
//   62     }
	DEC	R17
	RJMP	??OWI_ComputeCRC8_0
//   63     return seed;    
??OWI_ComputeCRC8_1:
	RET
        CFI EndBlock cfiBlock0
//   64 }
//   65 
//   66 
//   67 /*! \brief  Compute the CRC16 value of a data set.
//   68  *
//   69  *  This function will compute the CRC16 of inData using seed
//   70  *  as inital value for the CRC.
//   71  *
//   72  *  \param  inData  One byte of data to compute CRC from.
//   73  *
//   74  *  \param  seed    The starting value of the CRC.
//   75  *
//   76  *  \return The CRC16 of inData with seed as initial value.
//   77  *
//   78  *  \note   Setting seed to 0 computes the crc16 of the inData.
//   79  *
//   80  *  \note   Constantly passing the return value of this function 
//   81  *          As the seed argument computes the CRC16 value of a
//   82  *          longer string of data.
//   83  */

        RSEG CODE:CODE:NOROOT(1)
//   84 unsigned int OWI_ComputeCRC16(unsigned char inData, unsigned int seed)
OWI_ComputeCRC16:
        CFI Block cfiBlock1 Using cfiCommon0
        CFI Function OWI_ComputeCRC16
//   85 {
	MOV	R21,R16
//   86     unsigned char bitsLeft;
//   87     unsigned char temp;
//   88 
//   89     for (bitsLeft = 8; bitsLeft > 0; bitsLeft--)
	LDI	R20,8
??OWI_ComputeCRC16_0:
	CPI	R20,1
	BRCS	??OWI_ComputeCRC16_1
//   90     {
//   91         temp = ((seed ^ inData) & 0x01);
	MOV	R17,R18
	ANDI	R17,0x01
	MOV	R16,R21
	ANDI	R16,0x01
	EOR	R16,R17
	ANDI	R16,0x01
	MOV	R22,R16
//   92         if (temp == 0)
	TST	R22
	BRNE	??OWI_ComputeCRC16_2
//   93         {
//   94             seed >>= 1;
	LSR	R19
	ROR	R18
	RJMP	??OWI_ComputeCRC16_3
//   95         }
//   96         else
//   97         {
//   98             seed ^= 0x4002;
??OWI_ComputeCRC16_2:
	LDI	R16,2
	LDI	R17,64
	EOR	R18,R16
	EOR	R19,R17
//   99             seed >>= 1;
	LSR	R19
	ROR	R18
//  100             seed |= 0x8000;
	ORI	R19,0x80
//  101         }
//  102         inData >>= 1;
??OWI_ComputeCRC16_3:
	LSR	R21
//  103     }
	DEC	R20
	RJMP	??OWI_ComputeCRC16_0
//  104     return seed;    
??OWI_ComputeCRC16_1:
	MOVW	R17 : R16,R19 : R18
	RET
        CFI EndBlock cfiBlock1
//  105 }
//  106 
//  107 
//  108 /*! \brief  Calculate and check the CRC of a 64 bit ROM identifier.
//  109  *  
//  110  *  This function computes the CRC8 value of the first 56 bits of a
//  111  *  64 bit identifier. It then checks the calculated value against the
//  112  *  CRC value stored in ROM.
//  113  *
//  114  *  \param  romvalue    A pointer to an array holding a 64 bit identifier.
//  115  *
//  116  *  \retval OWI_CRC_OK      The CRC's matched.
//  117  *  \retval OWI_CRC_ERROR   There was a discrepancy between the calculated and the stored CRC.

⌨️ 快捷键说明

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