| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | //***************************************************************************** |
| 2 | // File Name : ds2450.c |
||
| 3 | // Title : Dallas 1-Wire DS2450 A2D Sensor Library |
||
| 4 | // Revision : 5 |
||
| 5 | // Notes : |
||
| 6 | // Target MCU : Atmel AVR series |
||
| 7 | // Editor Tabs : 4 |
||
| 8 | // |
||
| 9 | // Revision History: |
||
| 10 | // When Who Rev Description of change |
||
| 11 | // ----------- ----------- ------- ----------------------- |
||
| 12 | // 01-Oct-2003 rwatson 5 Fixed result error with MSB |
||
| 13 | // 30-Sep-2003 rwatson 4 CreatedDigitalOut |
||
| 14 | // 30-Sep-2003 rwatson 3 Created SetupAlll, StartAll, ResultAll, StartAndResultAll |
||
| 15 | // 29-Sep-2003 rwatson 2 Created Setup, Start, Result, StartAndResult |
||
| 16 | // 29-Sep-2003 rwatson 1 Created the program structure |
||
| 17 | //***************************************************************************** |
||
| 18 | |||
| 19 | #ifndef ds2450_h |
||
| 20 | #define ds2450_h |
||
| 21 | |||
| 22 | //----- Include Files --------------------------------------------------------- |
||
| 23 | #include "global.h" |
||
| 24 | |||
| 25 | //----- Defines --------------------------------------------------------------- |
||
| 26 | #define ds2450_rev 5 |
||
| 27 | |||
| 28 | // the two voltage ranges |
||
| 29 | #define DS2450_RANGE_2V 0x00 // 0-2.55V |
||
| 30 | #define DS2450_RANGE_5V 0x01 // 0-5.10V |
||
| 31 | |||
| 32 | // the family code |
||
| 33 | #define DS2450_FAMILY 0x20 |
||
| 34 | |||
| 35 | // the starting addresses |
||
| 36 | // of the pages in RAM |
||
| 37 | #define DS2450_DATA_PAGE 0x00 |
||
| 38 | #define DS2450_SETUP_PAGE 0x08 |
||
| 39 | #define DS2450_ALARM_PAGE 0x10 |
||
| 40 | |||
| 41 | #define DS2450_VCC_FLAG 0x40 |
||
| 42 | #define DS2450_VCC_ADDR 0x1C |
||
| 43 | |||
| 44 | // maximum allowable resolution |
||
| 45 | #define DS2450_RES_MAX 16 |
||
| 46 | |||
| 47 | // function commands |
||
| 48 | #define DS2450_READ_MEMORY 0xAA |
||
| 49 | #define DS2450_WRITE_MEMORY 0x55 |
||
| 50 | #define DS2450_CONVERT 0x3C |
||
| 51 | #define DS2450_CONVERT_ALL4_MASK 0x0F |
||
| 52 | #define DS2450_CLEAR_ALL4_MASK 0x55 |
||
| 53 | |||
| 54 | //----- Typedefs -------------------------------------------------------------- |
||
| 55 | |||
| 56 | // enumerated constant for configuring |
||
| 57 | // and controlling an A2D channel as a digital output |
||
| 58 | typedef enum {DIGOUT_LOW=0x80, DIGOUT_OC=0xC0, DIGOUT_DISABLE=0x00} dallas_a2d_out_T; |
||
| 59 | |||
| 60 | //----- Functions --------------------------------------------------------------- |
||
| 61 | |||
| 62 | // ds2450Init() |
||
| 63 | // initializes the dallas 1-wire bus |
||
| 64 | void ds2450Init(void); |
||
| 65 | |||
| 66 | //----- Single Channel Functions ---------------------------------------------- |
||
| 67 | // The following 4 functions are used for controlling a single channel on the |
||
| 68 | // a2d converter. If you are only using 1 channel, then these functions are |
||
| 69 | // faster. If you are using 2 or more channel, it is faster to use the All |
||
| 70 | // Channel Functions. This is because to convert all the channel only requires |
||
| 71 | // one command to the device, and then a read of the all the channel. To read |
||
| 72 | // two channel individually requires two commands to the device, and two reads. |
||
| 73 | // Therefore using the All Channel Functions for even just 2 channels is faster |
||
| 74 | // and more effificient. |
||
| 75 | |||
| 76 | // ds2450Setup() |
||
| 77 | // Sets up the given device, for the given channel [A-D], |
||
| 78 | // the given resolution [1-16] and the given range 0-2.55 or 0-5.10 |
||
| 79 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 80 | u08 ds2450Setup(dallas_rom_id_T* rom_id, u08 channel, u08 resolution, u08 range); |
||
| 81 | |||
| 82 | // ds2450Start() |
||
| 83 | // Starts the a2d conversion for the given device and the given channel [A-D] |
||
| 84 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 85 | u08 ds2450Start(dallas_rom_id_T* rom_id, u08 channel); |
||
| 86 | |||
| 87 | // ds2450Result() |
||
| 88 | // Gets the result from the a2d conversion |
||
| 89 | // for the given device and the given channel [A-D] |
||
| 90 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 91 | u08 ds2450Result(dallas_rom_id_T* rom_id, u08 channel, u16* result); |
||
| 92 | |||
| 93 | // ds2450StartAndResult() |
||
| 94 | // Starts the conversion of the given device and the given channel [A-D] |
||
| 95 | // Stores the result in the variable result |
||
| 96 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 97 | u08 ds2450StartAndResult(dallas_rom_id_T* rom_id, u08 channel, u16 *result); |
||
| 98 | |||
| 99 | //----- All Channel Functions ------------------------------------------------- |
||
| 100 | // The following 4 commands are used to access data from all 4 channels on the |
||
| 101 | // a2d converter. These commands should be used if you are using more than one |
||
| 102 | // channel on the device. See the Single Channel Functions description for |
||
| 103 | // more information |
||
| 104 | |||
| 105 | // ds2450SetupAll() |
||
| 106 | // Sets up the given device for all channels for the given resultion |
||
| 107 | // and the given range [0-2.55 or 0-5.10] |
||
| 108 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 109 | u08 ds2450SetupAll(dallas_rom_id_T* rom_id, u08 resolution, u08 range); |
||
| 110 | |||
| 111 | // ds2450StartAll() |
||
| 112 | // Starts the conversion for all 4 channels on the given a2d converter |
||
| 113 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 114 | u08 ds2450StartAll(dallas_rom_id_T* rom_id); |
||
| 115 | |||
| 116 | // ds2450ResultAll |
||
| 117 | // Gets the results from the given device |
||
| 118 | // and stores the result in the given array |
||
| 119 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 120 | u08 ds2450ResultAll(dallas_rom_id_T* rom_id, u16 result[4]); |
||
| 121 | |||
| 122 | // ds2450StartAndResultAll() |
||
| 123 | // 1-Step command to start the conversion for the given device, |
||
| 124 | // and store the results in the given array |
||
| 125 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 126 | u08 ds2450StartAndResultAll(dallas_rom_id_T* rom_id, u16 result[4]); |
||
| 127 | |||
| 128 | // ds2450Print() |
||
| 129 | // Does a formatted print on the given result for the given range |
||
| 130 | void ds2450Print(u16 result, u08 range); |
||
| 131 | |||
| 132 | //----- Digital Out Functions ------------------------------------------------- |
||
| 133 | // ds2450DigitalOut |
||
| 134 | // Use the given channel of the given device as a digital out |
||
| 135 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
| 136 | u08 ds2450DigitalOut(dallas_rom_id_T* rom_id, u08 channel, dallas_a2d_out_T state); |
||
| 137 | |||
| 138 | #endif |
Powered by WebSVN v2.8.3