Interface with DS18s20

I got a chance to look at this some more. I compared my write function to the one in the OneWire library and found that I had included two uncesessary lines; not sure why I did that.

//    pinMode(9,INPUT);
  //    digitalWrite(9,LOW);

When you remove the lines it works fine. So below is code that will interface with a single DS18s20 temperature sensor without using the OneWire library.

#include <OneWire.h>
#include <LiquidCrystal.h>
// LCD=======================================================
//initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define LCD_WIDTH 16
#define LCD_HEIGHT 2

void setup(void) 
{
  lcd.begin(LCD_WIDTH, LCD_HEIGHT,1);
  lcd.setCursor(0,0);
  lcd.print("DS1820 Test");
  Serial.begin(9600);
}
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract,i,y; 
char buf[20];

void loop(void) 
{
  byte data[12];

  reset();
  write(0xCC);
  write(0x44);         // start conversion, with parasite power on at the end

 
  digitalWrite(9,HIGH);
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  reset();
  write(0xCC);
  write(0xBE);         // Read Scratchpad


  for ( i = 0; i < 9; i++) 
  {           // we need 9 bytes
    data[i] = read();
    Serial.print(i);
    Serial.println(data[i]);
  }

  LowByte = data[0];
  HighByte = data[1];
  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (TReading*100/2);    

  Whole = Tc_100 / 100;  // separate off the whole and fractional portions
  Fract = Tc_100 % 100;

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print(Whole);
 lcd.print(".");
 lcd.print(Fract);
 
}

void reset(void)
{
  digitalWrite(9,LOW);
  pinMode(9,OUTPUT);
  delayMicroseconds(500);
  pinMode(9,INPUT);
  delayMicroseconds(420);
}



int write(int v) 
{
  for (i = 0; i <8; i++) {
    y = bitRead(v, i);
    if (y==1)
    { 
      digitalWrite(9,LOW);
      pinMode(9,OUTPUT);
      delayMicroseconds(10);
      digitalWrite(9,HIGH);
      delayMicroseconds(55);
  //    pinMode(9,INPUT);
  //    digitalWrite(9,LOW);
    }
    else
    {
      digitalWrite(9,LOW);
      pinMode(9,OUTPUT);
      delayMicroseconds(65);
      digitalWrite(9,HIGH);
      delayMicroseconds(5);
   //   pinMode(9,INPUT);
   //   digitalWrite(9,LOW);
    }
  }
}

int read()
{
  int val=0,i,val1=0;
  for (i=0; i<8; i++){
    pinMode(9,OUTPUT); 
    digitalWrite(9,LOW);
    pinMode(9,INPUT);
    val = digitalRead(9);
    delayMicroseconds(53);
    if (val == 1)
      bitSet(val1,i);
  }

  return val1;

}