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

📄 owiuartbitfunctions.lst

📁 达拉斯 1-Wire 主机通信 这份资料展示了如何把 1-Wire 主机通信在应用到一个AVR系统中
💻 LST
📖 第 1 页 / 共 2 页
字号:
   \   union <unnamed> volatile __io _A_PORTC
   \                     _A_PORTC:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x36, root
   \   union <unnamed> volatile __io _A_PINB
   \                     _A_PINB:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x37, root
   \   union <unnamed> volatile __io _A_DDRB
   \                     _A_DDRB:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x38, root
   \   union <unnamed> volatile __io _A_PORTB
   \                     _A_PORTB:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x39, root
   \   union <unnamed> volatile __io _A_PINA
   \                     _A_PINA:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x3a, root
   \   union <unnamed> volatile __io _A_DDRA
   \                     _A_DDRA:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x3b, root
   \   union <unnamed> volatile __io _A_PORTA
   \                     _A_PORTA:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x3c, root
   \   union <unnamed> volatile __io _A_EECR
   \                     _A_EECR:
   \   00000000                              DS 1

   \                                 In segment ABSOLUTE, at 0x3d, root
   \   union <unnamed> volatile __io _A_EEDR
   \                     _A_EEDR:
   \   00000000                              DS 1
Z:\qvcs\AVR318 Dallas 1-wire Communication Interface\Source Code\IAR\polled\OWIUARTBitFunctions.c
      1          // This file has been prepared for Doxygen automatic documentation generation.
      2          /*! \file ********************************************************************
      3          *
      4          * Atmel Corporation
      5          *
      6          * \li File:               OWIUARTFunctions.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:        Polled UART implementation of the basic bit-level
     16          *                         signalling in the 1-Wire(R) protocol.
     17          *
     18          *                         $Revision: 1.6 $
     19          *                         $Date: Thursday, August 19, 2004 09:02:02 UTC $
     20          ****************************************************************************/
     21          
     22          /*****************************************************************************
     23          *
     24          * Atmel Corporation
     25          *
     26          * File              : OWIUARTFunctions.c
     27          * Compiler          : IAR EWAAVR 3.20a
     28          * Revision          : $Revision: 1.6 $
     29          * Date              : $Date: Thursday, August 19, 2004 09:02:02 UTC $
     30          * Updated by        : $Author: tsundre $
     31          *
     32          * Support mail      : avr@atmel.com
     33          *
     34          * Supported devices : All AVRs with UART or USART module.
     35          *
     36          * AppNote           : AVR318 - 1-Wire(R) interface Master Implementation
     37          *
     38          * Description       : Polled UART implementation of the basic bit-level
     39          *                     signalling in the 1-Wire(R) protocol.
     40          *
     41          ****************************************************************************/
     42          
     43          #include "OWIPolled.h"
     44          
     45          #ifdef OWI_UART_DRIVER
     46          
     47          #include <ioavr.h>
     48          
     49          #include "OWIBitFunctions.h"
     50          
     51          
     52          
     53          /*! \brief Initialization of the one wire bus. (Polled UART driver)
     54           *  
     55           *  This function initializes the 1-Wire bus by configuring the UART.
     56           */
     57          void OWI_Init()
     58          {
     59              // Choose single or double UART speed.
     60              OWI_UART_STATCTRL_REG_A = (OWI_UART_2X << OWI_U2X);
     61          
     62              // Enable UART transmitter and receiver.
     63              OWI_UART_STATCTRL_REG_B = (1 << OWI_TXEN) | (1 << OWI_RXEN);
     64              
     65              // Set up asynchronous mode, 8 data bits, no parity, 1 stop bit.
     66              // (Initial value, can be removed)
     67          #ifdef URSEL
     68              OWI_UART_STATCTRL_REG_C = (1 << OWI_URSEL) | (1 << OWI_UCSZ1) | (1 << OWI_UCSZ0);
     69          #else
     70              OWI_UART_STATCTRL_REG_C = (1 << OWI_UCSZ1) | (1 << OWI_UCSZ0);
     71          #endif
     72          
     73              OWI_UART_BAUD_RATE_REG_L = OWI_UBRR_115200;    
     74          }
     75          
     76          
     77          /*! \brief  Write and read one bit to/from the 1-Wire bus. (Polled UART driver)
     78           *
     79           *  Writes one bit to the bus and returns the value read from the bus.
     80           *
     81           *  \param  outValue    The value to transmit on the bus.
     82           *
     83           *  \return The value received by the UART from the bus.
     84           */
     85          unsigned char OWI_TouchBit(unsigned char outValue)
     86          {
     87              // Place the output value in the UART transmit buffer, and wait
     88              // until it is received by the UART receiver.
     89              OWI_UART_DATA_REGISTER = outValue;
     90              while(!(OWI_UART_STATCTRL_REG_A & (1 << OWI_RXC)))
     91              {
     92          
     93              }
     94              // Set the UART Baud Rate back to 115200kbps when finished.
     95              OWI_UART_BAUD_RATE_REG_L = OWI_UBRR_115200;
     96              return OWI_UART_DATA_REGISTER;
     97          }
     98          
     99          /*! \brief Write a '1' bit to the bus(es). (Polled UART DRIVER)
    100           *
    101           *  Generates the waveform for transmission of a '1' bit on the 1-Wire
    102           *  bus.
    103           */
    104          void OWI_WriteBit1()
    105          {
    106              OWI_TouchBit(OWI_UART_WRITE1);
    107          }
    108          
    109          
    110          /*! \brief  Write a '0' to the bus(es). (Polled UART DRIVER)
    111           *
    112           *  Generates the waveform for transmission of a '0' bit on the 1-Wire(R)
    113           *  bus.
    114           */
    115          void OWI_WriteBit0()
    116          {
    117              OWI_TouchBit(OWI_UART_WRITE0);
    118          }
    119          
    120          
    121          /*! \brief  Read a bit from the bus(es). (Polled UART DRIVER)
    122           *
    123           *  Generates the waveform for reception of a bit on the 1-Wire(R) bus(es).
    124           *
    125           *  \return The value read from the bus (0 or 1).
    126           */
    127          unsigned char OWI_ReadBit()
    128          {
    129               // Return 1 if the value received matches the value sent.
    130               // Return 0 else. (A slave held the bus low).
    131               return (OWI_TouchBit(OWI_UART_READ_BIT) == OWI_UART_READ_BIT);
    132          }
    133          
    134          
    135          /*! \brief  Send a Reset signal and listen for Presence signal. (Polled 
    136           *  UART DRIVER)
    137           *
    138           *  Generates the waveform for transmission of a Reset pulse on the 
    139           *  1-Wire(R) bus and listens for presence signals.
    140           *
    141           *  \return A bitmask of the buses where a presence signal was detected.
    142           */
    143          unsigned char OWI_DetectPresence()
    144          {
    145              // Reset UART receiver to clear RXC register.
    146              OWI_UART_STATCTRL_REG_B &= ~(1 << OWI_RXEN);
    147              OWI_UART_STATCTRL_REG_B |= (1 << OWI_RXEN);
    148              
    149              // Set UART Baud Rate to 9600 for Reset/Presence signalling.
    150              OWI_UART_BAUD_RATE_REG_L = OWI_UBRR_9600;
    151              
    152              // Return 0 if the value received matches the value sent.
    153              // return 1 else. (Presence detected)
    154              return (OWI_TouchBit(OWI_UART_RESET) != OWI_UART_RESET); 
    155          }
    156          
    157          
    158          #endif


   Segment part sizes:

     Function/Label Bytes
     -------------- -----
     _A_EEAR           2
     _A_UBRRH          1
     _A_WDTCR          1
     _A_ASSR           1
     _A_OCR2           1
     _A_TCNT2          1
     _A_TCCR2          1
     _A_ICR1           2
     _A_OCR1B          2
     _A_OCR1A          2
     _A_TCNT1          2
     _A_TCCR1B         1
     _A_TCCR1A         1
     _A_SFIOR          1
     _A_OSCCAL         1
     _A_TCNT0          1
     _A_TCCR0          1
     _A_MCUCSR         1
     _A_MCUCR          1
     _A_TWCR           1
     _A_SPMCR          1
     _A_TIFR           1
     _A_TIMSK          1
     _A_GIFR           1
     _A_GICR           1
     _A_OCR0           1
     _A_SP             2
     _A_SREG           1
     _A_TWBR           1
     _A_TWSR           1
     _A_TWAR           1
     _A_TWDR           1
     _A_ADC            2
     _A_ADCSRA         1
     _A_ADMUX          1
     _A_ACSR           1
     _A_UBRRL          1
     _A_UCSRB          1
     _A_UCSRA          1
     _A_UDR            1
     _A_SPCR           1
     _A_SPSR           1
     _A_SPDR           1
     _A_PIND           1
     _A_DDRD           1
     _A_PORTD          1
     _A_PINC           1
     _A_DDRC           1
     _A_PORTC          1
     _A_PINB           1
     _A_DDRB           1
     _A_PORTB          1
     _A_PINA           1
     _A_DDRA           1
     _A_PORTA          1
     _A_EECR           1
     _A_EEDR           1

 
 64 bytes in segment ABSOLUTE
 
 0 bytes of DATA memory (+ 64 bytes shared)

Errors: none
Warnings: none

⌨️ 快捷键说明

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