>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >On Behalf Of XYZ XYZ >Sent: 17 June 2007 11:19 >To: piclist@mit.edu >Subject: [PIC] microchip c18 - 1wire lib > > >int gettemp(void) >{ > int buff[9], sensor, n; > int temperature; > sensor = 0; > > _1w_out_byte(0xcc, sensor); // skip ROM > > _1w_out_byte(0x44, sensor); // perform temperature conversion > _1w_strong_pull_up(sensor); > > _1w_init(sensor); > _1w_out_byte(0xcc, sensor); // skip ROM > > _1w_out_byte(0xbe, sensor); // read the result > > for (n=0; n<9; n++) > { > buff[n]=_1w_in_byte(sensor); > } > > > temperature = buff[0]>>1; // temperature without LSB (0.5C) > > return temperature; >} You must send a reset pulse before trying to send any commands. This is clearly described in the DS18B20 datasheet under the heading "Transaction Sequence" on page 10. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist