# [SOLVED]ds18b20 16f877 reading temperature problem

Status
Not open for further replies.

#### syenidogan

##### Member level 1
what is wrong with the code it is not displaying the correct temperature values ?

#### Attachments

• 1wirebus.zip
503.9 KB · Views: 13

#### udayan92

##### Full Member level 5
Do you mean to say that it is not displaying correct values on the LCD,or there is something wrong with the sensor?

#### syenidogan

##### Member level 1
Do you mean to say that it is not displaying correct values on the LCD,or there is something wrong with the sensor?

it is not displaying the correct values on simulation on proteus isis.

#### paulfjujo

hello

did you check the result of
Code:
unsigned char read_temperature(void)
before displaying on LCD ?

i don't know the OWS DS18b20, but could you confirm :
you take 2 bytes from DS18b20, but only keep MSB of each value to form the result
is it the good way ?
does it needs to use an integer to contain the result ?

#### syenidogan

##### Member level 1
hello

did you check the result of
Code:
unsigned char read_temperature(void)
before displaying on LCD ?

i don't know the OWS DS18b20, but could you confirm :
you take 2 bytes from DS18b20, but only keep MSB of each value to form the result
is it the good way ?
does it needs to use an integer to contain the result ?
İ need MSB of first byte (4 bits) and lsb of second byte (4bits). And first 4 bits will be my lsb and second 4 bits will be my MSB on the result byte.

İ dont know If read_byte function gets the correct value. But If i assign values for MSB And LSB variables on read_temperature function it is giving the correct values(the values i assigned) on the LCD . So read_byte function seems to be not getting bytes from ds18b20.

- - - Updated - - -

unsigned char read_temperature(void){ // Buffer length must be at least 12bytes long! ["+XXX.XXXX C"]
unsigned char LSB,MSB;
unsigned char digit=0; //Reset, skip ROM and start temperature conversion
bus_reset();
write_byte(CMD_SKIPROM);
write_byte(CMD_CONVERTTEMP);
DelayMs(750); //Wait until conversion is complet
write_byte(CMD_SKIPROM);
MSB=read_byte(); // here if I put MSB=0b11111001 ; instead of read_byte function then im getting the digit
// variable (return value) like 10011100 which is -100 and it is appearing on lcd.use
// but if i use read_byte function then it is not working. so here there is something wrong
//with the functions for 1 wire bus communication but i could see nothing wrong.

bus_reset(); //Store temperature integer digits
digit=LSB>>4;
digit|=(MSB&15)<<4;
return digit;
}

Last edited:

#### paulfjujo

hello,

I read the datasheet, and it seems that all the Scratchpad must be read (9 bytes) ?
Unfortunatly, i don't have this device to check by myself.
to be sure DS18B20 is visible on the OWS bus.
Are you confident with your delay_uS to build mS delay ?
maybe you can use a timer to do delay 750mS ?

- - - Updated - - -

Have a look on this LINK

syenidogan

### syenidogan

Points: 2

#### syenidogan

##### Member level 1
hello,

I read the datasheet, and it seems that all the Scratchpad must be read (9 bytes) ?
Unfortunatly, i don't have this device to check by myself.
to be sure DS18B20 is visible on the OWS bus.
Are you confident with your delay_uS to build mS delay ?
maybe you can use a timer to do delay 750mS ?

- - - Updated - - -

Have a look on this LINK
yes you can read all the bytes if you want or you can just reset bus after getting what you need.

thank you the problem was my delay routines. actually they were ok before with a different version of compiler or i was just thinking they were ok.

Status
Not open for further replies.