Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] ds18b20 16f877 reading temperature problem

Status
Not open for further replies.

syenidogan

Member level 1
Joined
Mar 6, 2014
Messages
41
Helped
2
Reputation
4
Reaction score
3
Trophy points
8
Activity points
297
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
Joined
Mar 2, 2014
Messages
284
Helped
40
Reputation
80
Reaction score
39
Trophy points
28
Location
India
Activity points
1,496
Do you mean to say that it is not displaying correct values on the LCD,or there is something wrong with the sensor?
Please explain..
 

syenidogan

Member level 1
Joined
Mar 6, 2014
Messages
41
Helped
2
Reputation
4
Reaction score
3
Trophy points
8
Activity points
297
Do you mean to say that it is not displaying correct values on the LCD,or there is something wrong with the sensor?
Please explain..


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

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,443
Helped
292
Reputation
584
Reaction score
277
Trophy points
1,363
Location
France 01800
Activity points
10,150
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
Joined
Mar 6, 2014
Messages
41
Helped
2
Reputation
4
Reaction score
3
Trophy points
8
Activity points
297
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
bus_reset(); //Reset, skip ROM and send command to read Scratchpad
write_byte(CMD_SKIPROM);
write_byte(CMD_RSCRATCHPAD);
LSB=read_byte(); //here if I put LSB=0b11001111 ; instead of read_byte function
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

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,443
Helped
292
Reputation
584
Reaction score
277
Trophy points
1,363
Location
France 01800
Activity points
10,150
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.
You don't check (read) the DS18b20 "Presence pulse" before start Skip ROM + Read Scratchpad ..
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

Member level 1
Joined
Mar 6, 2014
Messages
41
Helped
2
Reputation
4
Reaction score
3
Trophy points
8
Activity points
297
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.
You don't check (read) the DS18b20 "Presence pulse" before start Skip ROM + Read Scratchpad ..
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top