Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / apps / communication / 1-wire_mcu / mcu /

one_wire.h

   1  /*******************************************************************************
   2     main: rozhrani one wire
   3     Copyright (C) 2009 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Karel Slany <slany AT fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  
  44  *******************************************************************************/
  45  
  46  /*
  47   * Note:
  48   *
  49   * The source code is based o the source codes released in the following
  50   * application notes related to the DS18B20 digital thermometer device.
  51   *
  52   * AN126 - 1-Wire Communication Through Software
  53   * http://www.maxim-ic.com/app-notes/index.mvp/id/126
  54   * http://pdfserv.maxim-ic.com/en/an/AN126.pdf
  55   *
  56   * AN187 - 1-Wire Search Algorithm
  57   * http://www.maxim-ic.com/app-notes/index.mvp/id/187
  58   * http://pdfserv.maxim-ic.com/en/an/AN187.pdf
  59   *
  60   */
  61  
  62  
  63  #ifndef _ONE_WIRE_H_
  64  #define _ONE_WIRE_H_
  65  
  66  #define ROM_BYTES   8     // device ROM bytes
  67  #define MAX_DEVICES 5     // max. number of devices connected to the 1-wire bus
  68  
  69  extern unsigned char found_ROMs[MAX_DEVICES][ROM_BYTES];  // table of found ROM codes
  70  extern unsigned char num_ROMs;
  71  
  72  #define ow_get_num_dev() num_ROMs
  73  
  74  #define DQ_dir_out()     (P4DIR |= BIT3)
  75  #define DQ_dir_in()      (P4DIR &= (~BIT3))
  76  #define DQ_set_0()       (P4OUT &= (~BIT3))
  77  #define DQ_set_1()       (P4OUT |= BIT3)
  78  #define DQ_read()        ((P4IN & BIT3) == BIT3)
  79  
  80  #define FALSE 0
  81  #define TRUE 1
  82  
  83  
  84  /*******************************************************************************
  85   * TimerB delay function, behaviour defined by timerb_init() - period 0.5425us
  86  *******************************************************************************/
  87  void delay_1us083(unsigned long us);
  88  
  89  
  90  /*******************************************************************************
  91   * Delay macros used for 1-wire bus timing
  92  *******************************************************************************/
  93  #if defined MSP_16X
  94    #define delay_7us()   {unsigned char i = 3;   while(i) {asm("NOP"); i--;}}
  95    #define delay_60us()  {unsigned char i = 28;  while(i) {asm("NOP"); asm("NOP"); asm("NOP"); i--;}}
  96    #define delay_80us()  {unsigned char i = 37;  while(i) {asm("NOP"); asm("NOP"); asm("NOP"); i--;}}
  97    #define delay_420us() {unsigned char i = 205; while(i) {asm("NOP"); asm("NOP"); asm("NOP"); i--;}}
  98    #define delay_500us() {unsigned char i = 244; while(i) {asm("NOP"); asm("NOP"); asm("NOP"); i--;}}
  99  #elif defined MSP_261X
 100    #define delay_7us()   delay_1us083(7)
 101    #define delay_60us()  delay_1us083(56)
 102    #define delay_80us()  delay_1us083(74)
 103    #define delay_420us() delay_1us083(387)
 104    #define delay_500us() delay_1us083(460)
 105  #else
 106    #error "Unknown CPU type"
 107  #endif
 108  
 109  
 110  /*******************************************************************************
 111   * 1-wire bus reset
 112  *******************************************************************************/
 113  unsigned char ow_reset(void);
 114  
 115  
 116  /*******************************************************************************
 117   * read one bit
 118  *******************************************************************************/
 119  unsigned char ow_read_bit(void);
 120  
 121  
 122  /*******************************************************************************
 123   * write one bit
 124  *******************************************************************************/
 125  void ow_write_bit(unsigned char bit);
 126  
 127  
 128  /*******************************************************************************
 129   * read one byte
 130  *******************************************************************************/
 131  unsigned char ow_read_byte(void);
 132  
 133  
 134  /*******************************************************************************
 135   * write one byte
 136  *******************************************************************************/
 137  void ow_write_byte(unsigned char byte);
 138  
 139  
 140  /*******************************************************************************
 141   * 1-wire crc
 142  *******************************************************************************/
 143  unsigned char ow_crc(unsigned char x);
 144  
 145  
 146  /*******************************************************************************
 147   * searches for devices connected to the 1-wire
 148  *******************************************************************************/
 149  void ow_find_devices(void);
 150  
 151  
 152  /*******************************************************************************
 153   * perform match ROM
 154  *******************************************************************************/
 155  unsigned char ow_send_match_rom(unsigned char idx);
 156  
 157  
 158  #endif /* _ONE_WIRE_H_ */
 159  
Zobrazeno: 597124x Naposledy: 27.1.2022 14:45:27