Just thought this might be of interest to someone. It a routine to read = multiple 1 wire DS 18S20's and other 1-Wire on the same bus. ' One-wire multiple temperature sensors for upto 8 DS18S20 although this = is not the limit. ' Tested on a PROTON Board with a PIC16F877 at 20 Mhz ' Can be adapted easily for any PIC and board. I use Port A.0 for the 1 = wire ' Bus, and in this program I have already read the ID's with the = REMARKED part of ' the program using a single device routine. ' Conversion time is 750ms per device as laid out in 1 wire specs, = although you can ' test for end of conversion if speed is paramount. 5 volts must be sent = also to power=20 ' the devices when conversion is taking place, uses 1.5ma in conversion. = Can be a permanent supply. ' Three wires needed, GND, Data, +5Volts. This is supplied by the PIC on = Pin A.1 when converting. ' Also needs a 4K7 pull-up resistor between DQ and 5volts at pic input = pin. ' I also have an IBUTTON ports to read DS1990's on the same cable, used = for alarm setting and door access. ' PROTON BASIC PLUS used as its the best around. ' Any comments welcomed. ' dave.stowe@ntlworld.com ' Copyright Dave Stowe, June 2003 Include "PROTON_20.INC" ' Standard include for for 20 Mhz PIC = 16F877 =20 'Temperature Variables Dim Temperature as Word ' Temperature storage Dim Count_remain as Byte ' Count remaining Dim Count_per_c as Byte ' Count per degree C Dim Dum as Byte ' Dummy variable to pad OWIN =20 'Store Variables Dim Rom[8] As Byte ' Storage for the Device ID Dim Pointer as Byte ' Used in storing and retrieving the ID Dim Memloc as Word ' Where the data is held Dim Loop As Byte ' Used in getting data into Rom String =20 'For Displaying the Data Dim Sensor As Byte ' General loop counter for amount of = sensors =20 ' 1 Wire Bus pin assignment Symbol DQ =3D PORTA.0 ' One-wire data pin =20 =20 Main: ' Main program starts here=20 Delayms 500 ' Wait for PICmicro to stabilise Cls ' Clear the LCD =20 ' This bit when un-REMed will read Out the ROM ID's to the LCD for = adding to the CDATA below ' Must be only 1 device on the port at a time when reading ID's 'OWRITE DQ, 1, [$33] 'OREAD DQ ,0, [STR Rom\8] 'PRINT HEX2 ROM[0],HEX2 ROM[1],HEX2 rom[2], HEX2 ROM[3], HEX2 ROM[4], = HEX2 ROM[5], HEX2 ROM[6], HEX2 ROM[7] 'DELAYMS 15000 'CLS 'GOTO Main Sensors: For Sensor =3D 0 to 2 ' Loop round the Sensors Gosub GetSensor ' Get the Sensor Data Gosub Calculate ' Work out the temperature =20 ' A little line to display the Data, do all the work with the data in = here Print At 1, 1, "Sensor ",Dec Sensor + 1," =3D ",DEC (Temperature / = 100), ".", DEC2 Temperature DelayMs 250 ' A small delay so we can see the Temp Next ' and the next one please ! GoTo Sensors ' Do it forever Calculate: ' Calculate temperature in degrees C to 2 decimal places (not valid = for negative temperature) OREAD DQ, 0, [Temperature.LOWBYTE, Temperature.HIGHBYTE, = Dum,Dum,Dum,Dum, Count_remain, Count_per_c] Temperature =3D (((Temperature >> 1) * 100) - 25)=20 Temperature =3D Temperature + (((Count_per_c - Count_remain) * 100) / = Count_per_c) Return =20 =20 GetSensor:=20 ' Must have value of which sensor in Variable Sensor starting from 0 Pointer =3D Sensor * 8 : MemLoc =3D SensorData + Pointer 'Point to the = Rom Data For Loop =3D 0 to 7 Rom[Loop] =3D CREAD MemLoc + Loop ' Get the Rom Data Next Loop High PortA.1 ' Put 5 volt on power pins OWRITE DQ, 1, [$55,STR Rom,$44] ' Send Match Rom, Rom ID and = get temp command DelayMs 750 ' Wait for conversion OWRITE DQ, 1, [$55,STR Rom,$BE] ' Send Match Rom, Rom ID and = read the temperature LOW PortA.1 ' Turn off power Return =20 =20 SensorData: ' This is where we store the Rom ID's, must go in the program last ' This is laid out :- ' Family ID - 1 byte, Rom ID - 6 bytes, Checksum - 1 byte ' ROM ID is low byte first. As read by the routine above. CDATA $10,$8B,$D4,$43,$00,$08,$00,$B6 CDATA $10,$61,$E6,$43,$00,$08,$00,$57 CDATA $10,$F4,$AC,$43,$00,$08,$00,$59 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.486 / Virus Database: 284 - Release Date: 29/05/2003 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu