Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | //***************************************************************************** |
2 | // File Name : ds18b20.c |
||
3 | // Title : Dallas 1-Wire DS18B20 Temperature Sensor Library |
||
4 | // Revision : 3 |
||
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 | // 28-Sep-2003 rwatson 3 Added Print |
||
13 | // 27-Sep-2003 rwatson 2 Added Setup, Start, Result, StartAndResult |
||
14 | // 27-Sep-2003 rwatson 1 Created the program structure |
||
15 | //***************************************************************************** |
||
16 | |||
17 | #ifndef ds18b20_h |
||
18 | #define ds18b20_h |
||
19 | |||
20 | //----- Include Files --------------------------------------------------------- |
||
21 | #include "global.h" |
||
22 | |||
23 | //----- Defines --------------------------------------------------------------- |
||
24 | #define ds18b20_rev 3 |
||
25 | |||
26 | // family code |
||
27 | #define DS18B20_FAMILY 0x28 |
||
28 | |||
29 | // function commands |
||
30 | #define DS18B20_CONVERT_TEMP 0x44 |
||
31 | #define DS18B20_WRITE_SCRATCHPAD 0x4E |
||
32 | #define DS18B20_READ_SCRATCHPAD 0xBE |
||
33 | #define DS18B20_COPY_SCRATCHPAD 0x48 |
||
34 | #define DS18B20_RECALL_E2 0xB8 |
||
35 | #define DS18B20_READ_POWER 0xB4 |
||
36 | |||
37 | // resolution min and max |
||
38 | #define DS18B20_RES_MIN 9 |
||
39 | #define DS18B20_RES_MAX 12 |
||
40 | |||
41 | // no alarm values for high and low |
||
42 | #define DS18B20_NO_ALARM_LOW -56 // min temp read is -55C |
||
43 | #define DS18B20_NO_ALARM_HIGH 126 // max temp read is 125C |
||
44 | |||
45 | //----- Functions --------------------------------------------------------------- |
||
46 | |||
47 | // ds18b20Init() |
||
48 | // initializes the dallas 1-wire bus |
||
49 | void ds18b20Init(void); |
||
50 | |||
51 | // ds18b20Setup |
||
52 | // Sets up the device |
||
53 | // The parameters are the rom id of the device, |
||
54 | // the resolution [9-12], and the low and high alarm values. |
||
55 | // If no low and/or high alarm is desired, use the values -55 and/or 126 |
||
56 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
57 | u08 ds18b20Setup(dallas_rom_id_T* rom_id, u08 resolution, s08 alarm_low, s08 alarm_high); |
||
58 | |||
59 | // ds18b20Start() |
||
60 | // Start the conversion for the given device |
||
61 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
62 | u08 ds18b20Start(dallas_rom_id_T* rom_id); |
||
63 | |||
64 | // ds18b20Result() |
||
65 | // Gets the result of the conversion and stores it in *result |
||
66 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
67 | u08 ds18b20Result(dallas_rom_id_T* rom_id, u16 *result); |
||
68 | |||
69 | // ds18b20StartAndResult(); |
||
70 | // 1-step command to start the conversion and store the result in *result |
||
71 | // The conversion takes some time to do, so it can be more efficient |
||
72 | // to do the 1-step commands Start() and Result() |
||
73 | // Returns either the corresponding error or DALLAS_NO_ERROR |
||
74 | u08 ds18b20StartAndResult(dallas_rom_id_T* rom_id, u16 *result); |
||
75 | |||
76 | // ds18b20Print() |
||
77 | // Does a formatted print on the given resultat the given resolution: +xx x/xx |
||
78 | void ds18b20Print(u16 result, u08 resolution); |
||
79 | |||
80 | #endif |
Powered by WebSVN v2.8.3