1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
25 //---------------------------------------------------------------------------
27 // temp.c - Application to find and read the 1-Wire Net
28 // DS1920/DS1820/DS18S20 - temperature measurement.
30 // This application uses the files from the 'Public Domain'
31 // 1-Wire Net libraries ('general' and 'userial').
46 static void PrintSerialNum(uchar FamilySN[8]);
48 // local serial numbers
49 static uchar FamilySN[MAXDEVICES][8];
52 static int family_code;
56 char *argv[]={__FILE__, "exow"};
58 //----------------------------------------------------------------------
59 // Main Test for DS1920/DS1820 temperature measurement
61 int main() //short argc, char **argv)
70 //----------------------------------------
71 // Introduction header
72 printf("\n/---------------------------------------------\n");
73 printf(" Temperature application DS1920/DS1820 - Version 1.00 \n"
74 " The following is a test to excersize a DS1920/DS1820.\n"
75 " Temperature Find and Read from a: \n"
76 " DS1920/DS1820 (at least 1)\n\n");
78 printf(" Press any CTRL-C to stop this program.\n\n");
79 printf(" Output [Serial Number(s) ........ Temp1(C)] \n\n");
81 // check for required port name
84 printf("1-Wire Net name required on command line!\n"
85 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
86 "(Linux DS2480),\"1\" (Win32 TMEX)\n");
91 // attempt to acquire the 1-Wire Net
92 if (!owAcquire(portnum, argv[1], return_msg))
94 printf("%s",return_msg);
99 printf("%s",return_msg);
101 // Find the device(s)
102 NumDevices = FindDevices(portnum, &FamilySN[0], 0x10, MAXDEVICES);
106 printf("Device(s) Found: \n");
107 for (i = 0; i < NumDevices; i++)
109 PrintSerialNum(FamilySN[i]);
117 // read the temperature and print serial number and temperature
118 for (i = 0; i < NumDevices; i++)
121 if (ReadTemperature(portnum, FamilySN[i],¤t_temp))
123 PrintSerialNum(FamilySN[i]);
124 printf(" %5.2f \n", current_temp);
127 printf(" Error reading temperature, verify device present:%d\n",
128 owVerify(portnum, FALSE));
132 while (!key_abort());
135 printf("\n\n\nERROR, device DS1920/DS1820 not found!\n");
137 // release the 1-Wire Net
138 owRelease(portnum, return_msg);
139 printf("%s",return_msg);
145 // -------------------------------------------------------------------------------
146 // Read and print the serial number.
148 void PrintSerialNum(uchar FamilySN[8])
152 for (i = 7; i>=0; i--)
153 printf("%02X", FamilySN[i]);